akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;

struct CHT{
	using D = ll;
	typedef pair<D,D> P;
	vector<P> deq;
	int s,sd,t;
	void init(int N){
		deq.resize(N);
		s=0,sd=0,t=0;
	}
	void add(D a,D b){		//add ax+b     a:(広義)単調減少!!!
		b=-b;
		P p(a,b);
		while(s+1<t&&check(deq[t-2],deq[t-1],p)) t--;
		sd++;
		deq[t++]=p;
	}
	D incr_query(D x){		//x:単調増加の時,これを繰り返し呼ぶ(間にaddが挟まるのはOK)
		x=-x;
		while(s+1<t&&f(deq[s],x)>=f(deq[s+1],x)) s++;
		return -f(deq[s],x);
	}
	D decr_query(D x){		//x:単調減少の時,これを繰り返し呼ぶ(間にaddが挟まるのはOK)
		x=-x;
		if(sd>=t) sd=t-1;
//		while(sd+1<t&&f(deq[sd],x)>=f(deq[sd+1],x)) sd++;
		while(sd>0&&f(deq[sd],x)>f(deq[sd-1],x)) sd--;
		return -f(deq[sd],x);
	}
	D query(D x){
		x=-x;
		int lb=s-1,ub=t-1;
		while(ub-lb>1){
			int m=(lb+ub)/2;
			if(isright(deq[m],deq[m+1],x)) lb=m;
			else ub=m;
		}
		return -f(deq[ub],x);
	}

	bool isright(P& a,P& b,D x){
		return f(a,x)>=f(b,x);
	}
	bool check(P& a,P& b,P& c){
		return (b.fs-a.fs)*(c.sc-b.sc)>=(b.sc-a.sc)*(c.fs-b.fs);
	}
	D f(P &p,int x){
		return p.fs*x+p.sc;
	}
}cht;

ll inf=1e18;
const int MN=300000;
int N;
ll T[MN];

ll le[MN+1],ri[MN+1];

ll notuse[MN];
ll use[MN];

void calc(int L,int R){
	if(L==R) return;
	int m=(L+R)/2;
	
	//L<=j<=m<=p<i<=R
	cht.init(m-L+1);
	for(ll j=L;j<=m;j++) cht.add(-j,le[j]+(j*j-j)/2);
	ll mx=-inf;
	for(ll i=R;i>=m+1;i--){
		ll val=cht.incr_query(i)+(i*i+i)/2+ri[N-i];
		chmax(mx,val);
		chmax(use[i-1],mx);
	}

	//L<=j<=p<m<i<=R
	cht.init(R-m);
	for(ll i=m+1;i<=R;i++) cht.add(-i,ri[N-i]+(i*i+i)/2);
	mx=-inf;
	for(ll j=L;j<m;j++){
		ll val=cht.query(j)+(j*j-j)/2+le[j];
		chmax(mx,val);
		chmax(use[j],mx);
	}

	calc(L,m);
	calc(m+1,R);
}
int main(){
	cin>>N;
	rep(i,N) cin>>T[i];

	cht.init(N);
	le[0]=0;
	for(ll i=0;i<N;i++){
		cht.add(-i,le[i]+(i*i-i)/2);
		le[i+1]=max(le[i]+T[i],cht.query(i+1)+(i+1)*(i+2)/2);
	}
	cht.init(N);
	ri[0]=0;
	for(ll i=0;i<N;i++){
		cht.add(-i,ri[i]+(i*i-i)/2);
		ri[i+1]=max(ri[i]+T[N-1-i],cht.query(i+1)+(i+1)*(i+2)/2);
	}
	
	rep(i,N) notuse[i]=le[i]+T[i]+ri[N-1-i];

	ll sum=0;
	rep(i,N) sum+=T[i];

	calc(0,N);

//	rep(i,N) printf("use[%d]=%lld\n",i,use[i]);
//	rep(i,N) printf("notuse[%d]=%lld\n",i,notuse[i]);
	

	int M;
	cin>>M;
	rep(i,M){
		int p;
		ll x;
		cin>>p>>x;
		p--;
		ll ans=max(use[p],notuse[p]-T[p]+x);
		cout<<ans-(sum-T[p]+x)<<endl;
	}
}


Measured memory_bytes: 18944
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = max(a * 2 - 1, b * 2 - 1);
	ans = max(ans, a + b);
	cout << ans << endl;
}

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

int main() {

    long long n,i,a,b,cnt=0,d,f;
    cin >> n >> d;
    for(i=0;i<n;i++)
    {
        cin >> a >> b;
        f=a*a+b*b;
        if(f<=d*d)
            cnt++;
    }
    cout << cnt;
    

}


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

using namespace std;

string getWord(string line, bool first) {
  string word = "";
  bool passed = false;
  for (auto i: line) {
    if ((first && !passed && i != ' ') || (!first && passed)) {
      word += i;
    } else if (i == ' ') {
      passed = true;
    }
  }
  return word;
}

int main() {
	string line;
  	getline(cin, line);
    cout << getWord(line, false) << getWord(line, true);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<a; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
 
using namespace std;
 
const int mod=1e9+7;
const int maxn=100005;
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n;
	cin >> n;
	int e[n-1][2];
	loop(n-1) cin >> e[i][0] >> e[i][1];
	vector<int> adj[n+1];
	map<int,int> m;
	queue<int> q;
	loop(n-1){
		adj[e[i][0]].push_back(e[i][1]);
		adj[e[i][1]].push_back(e[i][0]);
	}
	bool visited[n+1];
	pii pre[n+1];
	int x;
	loop(n+1) visited[i]=false;
	loop(n+1) pre[i].second=0;
	q.push(1);
	pre[1].first=0;
	visited[1]=true;
	int color,maxcolor;
	maxcolor=0;
	while(!q.empty()){
		color=0;
		loop(adj[q.front()].size()){
			x=adj[q.front()][i];
			if(!visited[x]){
				color++;
				if(color==pre[q.front()].second) color++;
				if(color>maxcolor) maxcolor=color;
				//cout << color << "\n";
				q.push(x);
				pre[x].first=q.front();
				pre[x].second=color;
				visited[x]=true;
			}
		}
		q.pop();
	}
	cout << maxcolor << "\n";
	loop(n-1){
		if(pre[e[i][0]].first==e[i][1]) cout << pre[e[i][0]].second << "\n";
		else if(pre[e[i][1]].first==e[i][0]) cout << pre[e[i][1]].second << "\n";
	}
	return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b/a, c) << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h+2);
  rep(i,h+2) {
    string str = "";
    if (i == 0 || i == h+1){
      rep(j,w) str += '#';
    } else {
      cin >> str;
    }
    a.at(i) = '#' + str + '#';
  }
  rep(i,h+2){
    cout << a.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vll a(n);cin>>a[0];
    rep(i,n-1){
        cin>>a[i+1];
        a[i+1]+=a[i];
    }
    int la,ra,ma,lb,rb,mb,ansa,ansb;ll minimum,maximum;
    ll ans=INF;
    rep2(i,1,n-2){
        la=0;ra=i;
        while(ra-la>1){
            ma=(la+ra)/2;
            if(a[ma]<a[i]-a[ma])la=ma;
            else ra=ma;
        }
        if(abs(a[la]-(a[i]-a[la]))<abs(a[ra]-(a[i]-a[ra])))ansa=la;
        else ansa=ra;
        lb=i+1;rb=n-1;
        while(rb-lb>1){
            mb=(lb+rb)/2;
            if(a[mb]-a[i]<a[n-1]-a[mb])lb=mb;
            else rb=mb;
        }
        if(abs((a[lb]-a[i])-(a[n-1]-a[lb]))<abs((a[rb]-a[i])-(a[n-1]-a[rb])))ansb=lb;
        else ansb=rb;
        maximum=max(a[ansa],max(a[i]-a[ansa],max(a[ansb]-a[i],a[n-1]-a[ansb])));
        minimum=min(a[ansa],min(a[i]-a[ansa],min(a[ansb]-a[i],a[n-1]-a[ansb])));
        ans=min(ans,maximum-minimum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4820
import itertools

n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

for _ in range(n):
    s = input()
    if s[0] in 'MARCH' :
        names[s[0]] += 1

ans = 0
for (x,y,z) in itertools.combinations('MARCH',3) :
    ans += names[x]*names[y]*names[z]

print(ans)


Measured memory_bytes: 3060
l,r = map(int,input().split())

if r-l >= 2019:
    print("0")
    exit()
else:
    min = 2019
    for i in range(l,r):
        if min == 0:
            break
        else:
            for j in range(i+1,r+1):
                if i*j%2019 < min:
                    min = i*j%2019
                if min == 0:
                    break
print(min)

Measured memory_bytes: 3060
#include<cstdio>
#include<math.h>
#include<algorithm>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001;
#define LLINF 1001001001001001001001;
#define LL long long

int main(){
    int N,D,X;
    scanf("%d %d %d",&N,&D,&X);
    int ans=X;
    int A[102];
    rep(i,N){
        scanf("%d",&A[i]);
        ans+=int((D-1)/A[i])+1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.0000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007 
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> hoge;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		hoge.push_back(a);
	}
	sort(hoge.begin(), hoge.end());
	int ans = 0;
	long long now_itr = 0;
	for (int i = 0; i < n - 1; ++i) {
		if (min(hoge[i], hoge[n - 1] - hoge[i]) > ans) {
			ans = max(ans, min(hoge[i], hoge[n - 1] - hoge[i]));
			now_itr = hoge[i];
		}
	}
	cout << hoge[n - 1] << " " << now_itr << endl;
	return 0;
}

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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (0 <= x - r && 0 <= y - r && x + r <= W && y + r <= H)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for (register int i=0;i<s.size();++i){
		if (s[i]=='C')
		for (register int j=i+1;j<s.size();++j){
			if (s[j]=='F'){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long x,a,b,c;
	scanf("%lld",&x);
	a=100;
	b=1;
	c=0;
	while(1){
		a=a+b;
		b=a/100;
		c++;
		if(a>=x) break;
	}
	printf("%lld\n",c);
	return 0;
}


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



signed main(){
    // cout << fixed << setprecision(10) << flush;

    string s;
    cin >> s;

    int ans = 0;
    for(int i=0; i<(1LL<<(s.size()-1)); i++){
        int num = 0;
        for(int j=0; j<s.size()-1; j++){
            num = num * 10 + s[j] - '0';
            if(i & (1LL<<j)){
                ans += num;
                num = 0;
            }
        }
        ans += num * 10 + s[s.size()-1] - '0';
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
INF = float('inf')
N = int(input())
h = list(map(int, input().split()))

# dp[i] : 足場i+1まで到達する最小のコスト
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(
                dp[i - 1] + abs(h[i - 1] - h[i]),
                dp[i - 2] + abs(h[i - 2] - h[i])
                )

print(dp[N - 1])


Measured memory_bytes: 85188
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int a, b, c, d, e, k, d1, d2, d3, d4, d6, d7, d8, d10, d11, d13;
    cin >> a >> b >> c >> d >> e >> k;
    d1 = abs(a - b);
    d2 = abs(a - c);
    d3 = abs(a - d);
    d4 = abs(a - e);
    
    d6 = abs(c - b);
    d7 = abs(d - b);
    d8 = abs(e - b);
    
    d10 = abs(c - d);
    d11 = abs(c - e);
    
    d13 = abs(d - e);

    if(d1 > k or d2 > k or d3 > k or d4 > k or d6 > k or d7 > k or d8 > k or d10 > k or d11 > k or d13 > k)
        cout << ":(";
    else cout << "Yay!";
    
    return 0;
}

Measured memory_bytes: 3632
n = gets.to_i
m = gets.to_i

cards = (1..2*n).to_a

m.times do
  k = gets.to_i
  if k == 0
    new_cards = []
    n.times do |i|
      new_cards[2*i]   = cards[i]
      new_cards[2*i+1] = cards[n+i]
    end
    cards = new_cards
  else
    cards = cards[k..2*n] + cards[0..k-1]
  end
end

cards.each do |card|
  puts card
end

Measured memory_bytes: 7364
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;

using ll = long long;
using boost::irange;

int main(){

    int H, W, A, B;
    cin >> H >> W >> A >> B;

    bool x;
    for (int h: irange(0, H)){
        if (h < B) x = true;
        else x = false;

        for (int w: irange(0, W)){
            if (w < A) cout << (int)x;
            else cout << (int)(!x);
        }
        cout << endl;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string S;
	cin >> S;
	reverse(S.begin(), S.end());

	const int mod = 1000000007;

	vector<vector<ll>> dp(S.size() + 1, vector<ll>(13));
	dp[0][0] = 1;
	int keta = 1;
	for (int i = 1;i <= S.size();i++) {
		for (int j = 0;j < 10;j++) {
			if (S[i - 1] == '?' || S[i - 1] == j + '0') {
				for (int k = 0;k < 13;k++) {
					dp[i][(keta * j + k) % 13] += dp[i - 1][k];
					dp[i][(keta * j + k) % 13] %= mod;
				}
			}
		}
		keta = (keta * 10) % 13;
	}
	cout << dp[S.size()][5] << endl;

	return 0;
}


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


int main(){
    ll n, k;    cin >> n >> k;

    char c[3] = {'s', 'p', 'r'};
    map<char, ll> mp;
    rep(i, 3){
        ll x;   cin >> x;
        mp[c[i]] = x;
    }
    vector<ll> dp(n, 0);
    string t;   cin >> t;
    rep(i, n){
        ll nv = i-k;
        if(nv<0) dp[i] = 1;
        else dp[i] = (t[i]!=t[i-k] || !dp[i-k]);
    }
    ll res=0;
    rep(i, n){
        if(dp[i]) res += mp[t[i]];
        //cout << res << ' ';
    }
    cout << res << endl;   

}


Measured memory_bytes: 4328
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
#define ll long long

int main(){

    int n; cin >> n;

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

    int b[n];
    bool isPossible;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            isPossible = true;
            for(int k=0; k<n; k++){
                if(k == i){
                    b[k] = p[j];
                }
                else if(k == j){
                    b[k] = p[i];
                }
                else{
                    b[k] = p[k];
                }
            }
            for(int k=1; k<n; k++){
                if(b[k] < b[k-1]){
                    isPossible = false;
                }
            }
            if(isPossible) break;
        }
        if(isPossible) break;
    }

    bool tempPossible = true;
    for(int i=1; i<n; i++){
        if(p[i] < p[i-1]){
            tempPossible = false;
        }
    }
    if(tempPossible) isPossible = true;
    
    if(isPossible){
        cout << "YES";
    }
    else{
        cout << "NO";
    }

    return 0;
}

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

int main(void) {
  int W, H, N, xmin, xmax, ymin, ymax;
  cin >> W >> H >> N;
  xmin = ymin = 0;
  xmax = W;
  ymax = H;

  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) xmin = max(xmin, x);
    if (a == 2) xmax = min(xmax, x);
    if (a == 3) ymin = max(ymin, y);
    if (a == 4) ymax = min(ymax, y);
  }
  cout << max(0, (xmax - xmin)) * max(0, (ymax - ymin)) << endl;
  return 0;
}

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

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

    int total_t = 0;
    vector<int> t(n), v(n);
    for(int i=0; i<n; i++){
        cin >> t[i];
        total_t += t[i];
    }
    for(int i=0; i<n; i++){
        cin >> v[i];
    }

    vector<int> maxv(2 * total_t+1, 1000);// in 0.5 increment
    maxv[0] = 0;
    maxv[2*total_t] = 0;
    int current = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=2*t[i]; j++){
            //cout << current + j << " ";
            if(current + j <= 2 * total_t / 2) maxv[current + j] = min({maxv[current + j], 2 * v[i], current + j});
            else maxv[current + j] = min({maxv[current + j], 2 * v[i], 2 * total_t - (current + j)});
            //cout << maxv[current + j] << endl;
        }
        current += 2 * t[i];
    }
    for(int i=1; i<=2*total_t; i++){
        for(int j=i+1; j<=2*total_t; j++){
            maxv[i] = min(maxv[i], maxv[j] + (j-i));
        }
        //cout << i << " " << maxv[i] << endl;
    }

    double ans = 0;
    int current_v = 0;
    for(int i=1; i<=2*total_t; i++){// be careful with the scaling by 2
        if(current_v < maxv[i]){
            current_v += 1;
            ans += (current_v / 2.0 + (current_v-1) / 2.0) * 0.5 / 2.0;// trapezoid
        }
        else if(current_v > maxv[i]){
            current_v -= 1;
            ans += (current_v / 2.0 + (current_v+1) / 2.0) * 0.5 / 2.0;// trapezoid
        }
        else{// current_v == maxv[i]
            ans += (current_v / 2.0) * 0.5;// rectangle
        }
        //cout << i << " : " << current_v / 2.0 << endl;
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 512
//let input = "5\n3 3 3 3 3";

function main(input){
  input = input.trim();
  let lines = input.split("\n");
  //console.log(lines);
  let list = lines[1].split(" ");
  let count = 0;
  for(let i=0; i<list.length; i++){
    list[i] = parseInt(list[i]);
    if(i !== 0){
      let fumidai = list[i-1] - list[i];
      if(fumidai < 0){fumidai = 0;}
      list[i] += fumidai;
      count += fumidai;
    }
  }
  console.log(count);
}

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

Measured memory_bytes: 49068
n = int(input())

A = []
x = []
y = []
x_dash = []
y_dash = []
ans = []
for i in range(n):
	A.append(int(input()))
	x_dash = []
	y_dash = []
	for j in range(A[i]):
		x_dash_dash,y_dash_dash = map(int,input().split())
		x_dash.append(x_dash_dash)
		y_dash.append(y_dash_dash)
	tmp = x_dash
	x.append(tmp)
	tmp = y_dash
	y.append(tmp)

for i in range(2**n):
	a = [0]*n
	count = 0
	for j in range(n):
		if i & (1<<j):
			a[j] = 1

	for j in range(n):
		flag = False
		if a[j] == 1:
			for k in range(A[j]):
				if a[x[j][k]-1] != y[j][k]:
					flag = True
					break
		if flag:
			break
	if not flag:
		ans.append(a.count(1))
		ans.append(count)

print(max(ans))

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
const double eps = 1e-4;
int w, h, n;
struct Point
{
	double x, y;
	void in(){scanf("%lf%lf", &x, &y);}
}p[N];
inline int sgn(double x){return x < -eps ? -1 : x > eps ? 1 : 0;}
struct edge{int next, to;} e[N*N];
int head[N], tot;
void gInit(){memset(head, -1, sizeof(head)); tot = 0;}
void add_edge(int u,int v){e[tot] = (edge){head[u], v}; head[u] = tot++;}
bool vis[N];
double dist(const Point &a, const Point &b)
{
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool solve(double x)
{
	gInit();
	for(int i = 1; i <= n; ++i)
		if(sgn(p[i].x - x) < 0)
			add_edge(0, i);
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			if(sgn(dist(p[i], p[j]) - x - x) < 0)
			{
				add_edge(i, j);
				add_edge(j, i);
			}
	for(int i = 1; i <= n; ++i)
		if(sgn(w - p[i].x - x) < 0)
			add_edge(i, n + 1);
	queue<int> que;
	que.push(0);
	memset(vis, false, sizeof(vis));
	vis[0] = true;
	while(!que.empty())
	{
		int u = que.front(); que.pop();
		for(int i = head[u]; ~i; i = e[i].next)
			if(!vis[e[i].to])
			{
				vis[e[i].to] = true;
				que.push(e[i].to);
			}
	}
	if(vis[n + 1]) return false;
	//check start point and end point
/*	Point w0 = (Point){w, 0};
	Point wh = (Point){w, h};
	for(int i = 1; i <= n; ++i)
	{
		if(!vis[i]) continue;
		if(sgn(dist(w0, p[i]) - x) <= 0) return false;
		if(sgn(dist(wh, p[i]) - x) <= 0) return false;
	}
*/
	return true;
}
int main()
{
	scanf("%d%d%d", &w, &h, &n);
	for(int i = 1; i <= n; ++i) p[i].in();
	double l = 0, r = 1e10, mid, ans = 0.0;
	for(int i = 0; i < 100; ++i)
	{
		mid = 0.5 * (l + r);
		if(solve(mid))
		{
			ans = mid;
			l = mid;
		}
		else
		{
			r = mid;
		}
	}
	printf("%.3f", ans);
	return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

using namespace std;


int main(){
   int n;
   cin>>n;
   vector<int> a(n,0);
   rep(i,n){
      cin>>a[i];
   }
   sort(a.begin(),a.end());

   double ans=a[0];

   for(int i=1;i<n;i++){
      ans+=a[i];
      ans/=2.0;
   }

   cout<<setprecision(10)<<ans;


return 0;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	c := 0
	for i := 0; i < n-2; i++ {
		if s[i:i+3] == "ABC" {
			c++
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MN 101000

typedef long long ll;
int n, m;
ll q[MN];
int st[MN], top = 0;
ll f[MN], g[MN];

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 0; i <= m; i++)
	{
		if(i) scanf("%lld", &q[i]);
		else q[0] = n;
		while(top && q[i] <= q[st[top]]) top--;
		st[++top] = i;
	}
	
	for(int i = 1; i <= top; i++) q[i - 1] = q[st[i]];
	top--; f[top] = 1;
	for(int i = top; i >= 1; i--)
	{
		ll x = q[i];
		while(x >= q[0])
		{
			int p = std::upper_bound(q, q + top + 1, x) - q - 1;
			if(p == i) p--;
			f[p] += f[i] * (x / q[p]);
			x %= q[p];
		}
		if(x) g[x] += f[i];
	}
	g[q[0]] += f[0];
	for(int i = n; i >= 1; i--) g[i] += g[i + 1];
	for(int i = 1; i <= n; i++) printf("%lld\n", g[i]);
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int MAX_N=100005;
int dp[MAX_N];
int main()
{
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	rep(i,1,MAX_N)
	{
		rep(j,0,7)
		{
			dp[i]=min(dp[i],dp[i-1]+1);
			if(i>=pow(6,j))dp[i]=min(dp[i],dp[i-(int)pow(6,j)]+1);
			if(i>=pow(9,j))dp[i]=min(dp[i],dp[i-(int)pow(9,j)]+1);
		}
	}
	cout<<dp[read()]<<endl;
	return 0;
}



Measured memory_bytes: 640
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e17
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;cin>>n;
    vector<ll>a(n);
    map<ll,ll>m;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    if(m[0]>1){
        cout<<0<<endl;
        return 0;
    }

    for(ll i=1;i<n;i++){
    if(m[i]!=2&&m[i]!=0){
        cout<<0<<endl;
        return 0;
    }
    }
    n/=2;
    ll ans=1;
    while(n--){
        ans*=2;
        ans%=MOD;
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------








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

typedef long long ll;

string Name(ll N){
  string str;
  while(N>0){
    N--;
    char c='a'+(N%26);
    str.push_back(c);
    N/=26;
  }
  return str;
}

int main(){
  ll N;
  cin >> N;
  
  string s=Name(N);
  for(int i=s.size()-1; i>=0; i--){
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, M;
    cin >> N >> M;
    cout << N*(N-1)/2 + M*(M-1)/2 << "\n";
}

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

map<ll,ll> m;

ll dfs(ll rem){
    if(rem==0) return 0;
    if(m[rem]!=0)return m[rem];
    return m[rem]=1+dfs(rem/2)*2;
}
int main() {
    ll h;
    std::cin >> h;
    std::cout << dfs(h) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef unsigned long long ull;

const int MOD = 1000000007 ; //  , 1000000009 , 1000000023 ,998244353
const ll INF = ll(1e18);
const ld PI = 4*atan((ld)1);

ll power(ll x,ll n) {
  ll result=1;
  while(n>0){
    if(n&1)result = (result * x)%MOD;
    x=(x*x)%MOD;
    n >>= 1;
  }
  return result%MOD;
}
ll gcd(ll a,ll b){
  if(a==0)return b;
  return gcd(b%a,a);
}
int main() {
  #ifdef AVI  
    freopen("input.txt" , "r" , stdin);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);

  ll n,m;
  cin >> n >> m;
  ll ar[n][m];
  for(ll i=0 ; i<n ; i++){
    for(ll j=0 ; j<m ; j++){
      char x;
      cin >> x;
      if(x=='.')ar[i][j] = 1;
      else ar[i][j] = 0;
    }
  }
  ll dp[n][m] , x = 1;
  for(ll i=0 ; i<m  ; i++){
    if(ar[0][i]==0)x = 0;
    dp[0][i] = x;
  }
  x = 1;
  for(ll i=0 ; i<n ; i++){
    if(ar[i][0]==0)x = 0;
    dp[i][0] = x;
  }
  for(ll i=1 ; i<n ; i++){
    for(ll j=1 ; j<m ; j++){
      dp[i][j] = 0;
      if(ar[i][j]==0 || (dp[i-1][j]==0 && dp[i][j-1]==0)){
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] += (dp[i-1][j] + dp[i][j-1])%MOD;
      dp[i][j] %= MOD; 
    }
  }/*
  for(ll i=0 ; i<n ; i++){
    for(ll j=0 ; j<m ; j++){
      cout << dp[i][j] << ' ';
    }
    cout << '\n';
  }*/
  cout << dp[n-1][m-1];
}

Measured memory_bytes: 15872
h,w=map(int, input().split())
s=[' '*(w+2)]
for _ in range(h):
    s.append(' '+input()+' ')
s.append(' '*(w+2))

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[j][i]=='#':
            if s[j-1][i]!='#' and s[j+1][i]!='#' and s[j][i-1]!='#' and s[j][i+1]!='#' :
                    print('No')
                    exit()
print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  string s;
  cin >> s;
  I t=0;
  I r=0,b=0;
  REP(i,s.size()){
    if (s.at(i) == '1'){
      b++;
    }else{
      r++;
    }
  }
  t = s.size() - abs(r-b);
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 512
b,a=map(int,input().split())
if a==1 or b==1:
    print(1)
else:
    if a%2==0:
        val=int(a/2)
        print(val*b)
    else:
        val=int(a/2)+1
        if b%2==0:
            print(val*int(b/2)+(val-1)*int(b/2))
        else:
            print(val*int(b/2)+(val-1)*int(b/2)+val)

Measured memory_bytes: 3060
from itertools import permutations

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
T = [A, B, C, D, E]

res = 10 ** 9
for s in permutations(range(5), 5):
    cnt = T[s[0]]
    for i in s[1:]:
        if cnt % 10 != 0:
            cnt += 10 - cnt % 10
        cnt += T[i]
    res = min(res, cnt)

print(res)


Measured memory_bytes: 3064
#include<stdio.h>
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	int K;
	long long cnt=0;
	scanf("%d",&K);
	for(int i=1;i<K+1;i++){
		for(int j=1;j<K+1;j++){
			for(int k=1;k<K+1;k++){
				cnt+=gcd(gcd(i,j),k);
			}
		}
	}
	printf("%lld",cnt);
}

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

using namespace std;

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

    vector<int> usum(N), bsum(N);
    usum[0] = A[0][0];
    bsum[N-1] = A[1][N-1];
    for (int i = 1; i < N; i++) {
        usum[i] = usum[i-1] + A[0][i];
        bsum[N-1-i] = bsum[N-i] + A[1][N-1-i];
    }
    int msum = 0;
    for (int i = 0; i < N; i++) {
        msum = max(msum, usum[i] + bsum[i]);
    }
    
    cout << msum << endl;
}

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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define fastio ios::sync_with_stdio(false); cin.tie(0)

int main(){
    fastio;
    int n, k;
    cin >> n >> k;
    k--;
    cout << n-k << endl;
    return 0;
}

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

int main(){

  int n, q;

  while(cin>>n>>q, n){
    int cnt[101]={}, ma=0, md;
    for(int i=0;i<n;i++){
      int m;
      cin>>m;
      for(int j=0;j<m;j++){
	int d;
	cin>>d;
	cnt[d]++;
	if(ma<cnt[d]){
	  ma=cnt[d];
	  md=d;
	}
	if(ma==cnt[d]&&md>d) md=d;
      }
    }
    if(ma<q) cout<<0<<endl;
    else cout<<md<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3004
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<functional>
#include<cmath>
#include<algorithm>
typedef  long long ll;

int main() {
	int  n = 0,f = 0;
	int a[100000] = {};
	std::map<int, int> count;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			f = a[i] / 2;
			if ( f%2 == 0) {
				count[3]++;
				goto mel;
			}
			count[2]++;
		}
		else {
			count[1]++;
		}
		mel:
		f = 0;
	}
	
	if (count[2] > 0) {
		if (count[3] >= count[1]) {
			std::cout << "Yes" << std::endl;
		}
		else {
			std::cout << "No" << std::endl;
		}
	}
	else {
		if (count[3]+1 >= count[1]) {
			std::cout << "Yes" << std::endl;
		}
		else {
			std::cout << "No" << std::endl;
		}
	}
}


Measured memory_bytes: 640
package main

import(
	"fmt"
)

func main() {
	var a int
	var b int
	var c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	if a + b == c {
		fmt.Println("Yes")
	} else if a + c == b {
		fmt.Println("Yes")
	} else if b + c == a {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

int main(){
    int N ;
    cin >> N ;
    int arr[N+1] ;
    for( int i = 0 ; i < N ; i++ ) cin >> arr[i] ;
    int dp[N+1] ;
    memset( dp, 0, sizeof(dp) ) ;
    dp[1] = abs( arr[1] - arr[0] ) ;
    for( int i = 2 ; i < N ; i++ ){
        dp[i] = min( dp[i-2] + abs(arr[i] - arr[i-2]), dp[i-1] + abs(arr[i]-arr[i-1]) ) ;
    }
    cout << dp[N-1] << "\n" ;

    return 0 ;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 7;
#define debug(a) cout<<#a<<": "<<a<<'\n'
/*
unique 返回的是重复元素的首地址 
*/
ll read(){
	ll ans = 0,f = 1;
	char ch = getchar();
	for(;ch<'0'||ch>'9';ch =getchar())if(ch=='-')f = -1;
	for(;ch>='0'&&ch<='9';ch = getchar())ans = (ans<<3) + (ans << 1) + ch-'0';
	return ans * f;
}
int n;
int a[maxn],b[maxn],c[maxn],d[maxn],f[maxn],sz[maxn],ans;
int _find(int x){return  f[x] == x ? x : f[x] = _find(f[x]);}
void _union(int x,int y){
	int hx = _find(x),hy = _find(y);
	f[hx] = hy;
}
map<int,int> p;
int main() {
	//ios::sync_with_stdio(false);
	scanf("%d",&n);
	int sa = 0,sb = 0;
	for(int i = 1;i <= n;++i)scanf("%d",&a[i]),c[i] = a[i],sa ^= a[i];
	for(int i = 1;i <= n;++i)scanf("%d",&b[i]),d[i] = b[i],sb ^= b[i];
	c[n+1] = a[n+1] = sa;
	d[n+1] = b[n+1] = sb;
	sort(c+1,c+2+n);sort(d+1,d+2+n);
	for(int i = 1;i <= n;++i)
		if(c[i]!=d[i]){
		printf("-1");
		return 0;
	}
	int cnt = 0;
	for(int i = 1;i < n+1;++i)
		if(a[i]!=b[i])cnt++;
	if(cnt == 0){
		printf("0\n");
		return 0;
	}
	cnt = 0;
	for(int i = 1;i < n + 1;++i){
		if(a[i]==b[i])continue;    
		ans++;
		if(!p[a[i]])p[a[i]] = ++ cnt;
		if(!p[b[i]])p[b[i]] = ++ cnt;
	}
	if(!p[a[1+n]])p[a[1+n]] = ++ cnt;
	if(!p[b[1+n]])p[b[1+n]] = ++ cnt;
	for(int i = 1;i <= cnt;++i)f[i] = i;
	for(int i = 1;i <= n + 1;++i){
		if(a[i]==b[i])continue;    
		_union(p[a[i]],p[b[i]]);
	}
	//if(f[a[n+1]==a[n+1]&&sz[a[n+1]]]==1)++ans;
	for(int i = 1;i <= cnt;++i)
		if(f[i]==i)++ans;
	printf("%d",ans-1);
	return 0;
}

Measured memory_bytes: 20864
#AtCorder Beginner Contest 110 B 1 Dimensional World's Tale
import sys
N,M,X,Y = input().split()

X = int(X)
Y = int(Y)

x = list(map(int, input().split()))
y = list(map(int, input().split()))

maxX = max(x)
minY = min(y)

if maxX >= minY:
    print("War")
else:
    for Z in range(maxX+1,minY+2):
        if ( X < Z and Z <= Y ) and ( maxX < Z and minY >=Z ):
            print("No War")
            sys.exit()
        else:
            print("War")
            sys.exit()

Measured memory_bytes: 3064
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {
	long A, B; cin >> A >> B; cout << max(max(A + B, A - B), A * B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>
#include <queue>

typedef long long ll;

using namespace std;


static int un[200000];

int root(int x){
    if(un[x] == x) return x;
    return un[x] = root(un[x]);
}
void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    if(rx > ry){
        un[rx] = ry;
    } else {
        un[ry] = rx;
    }
}


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

    for(int i = 0; i < n; i++){
        un[i] = i;
    }

    int cntf[n];
     for(int i = 0; i < n; i++){
        cntf[i] = 0;
    }

    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        unite(x - 1, y - 1);
        /*
        if(un[x - 1] > un[y - 1]){
            int r =  un[x - 1];
            un[r] = un[y - 1];
        } else {
            int r = un[y - 1];
            un[r] = un[x - 1];
        }
        */
        cntf[x - 1]++;
        cntf[y - 1]++;
    }

    for(int i = 0; i < n; i++){
        root(i);
    }

    int cnt[n];
    for(int i = 0; i < n; i++){
        cnt[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cnt[un[i]]++;
    }

    int cntk[n];
     for(int i = 0; i < n; i++){
        cntk[i] = 0;
    }
    for(int i = 0; i < k; i++){
        int x, y;
        cin >> x >> y;
        if(un[x - 1] == un[y - 1]){
            cntk[x - 1]++;
            cntk[y - 1]++;
        }
    }

    for(int i = 0; i < n; i++){
        int ans = cnt[un[i]] - cntf[i] - cntk[i] - 1;
        cout << ans;
        if(i == n - 1){
            cout << endl;
        } else {
            cout << " ";
        }
    }
}

Measured memory_bytes: 2432
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextLine()) {
			String reverse = sc.nextLine();
			char[] a = reverse.toCharArray();
			char[] b = new char[a.length];
			int j = 0;
			for (int i = a.length - 1; i >= 0; i--) {
				b[j] = a[i];
				j++;
			}
			System.out.println(b);
		}
	}
}

Measured memory_bytes: 17128
#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    int n;
    cin >> n;
    vector <vector <int> > a(2, vector <int> (n));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    vector <vector <int> > d(2, vector <int> (n, 0));
    d[0][0] = a[0][0];
    d[1][0] = a[0][0] + a[1][0];
    for (int j = 1; j < n; j++) {
        d[0][j] = d[0][j - 1] + a[0][j];
        d[1][j] = max(d[1][j - 1], d[0][j]) + a[1][j];
    }
    cout << d[1][n - 1];
}


Measured memory_bytes: 256
import bisect
import functools
import os
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        ret = fn(*args, **kwargs)
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        print(ret)
        return ret

    return wrapper


@debug
def calc_bit(k):
    """
    答えの下から k ビット目を返す
    :param int k:
    :return:
    """
    # 答えの k ビット目が偶数なら 0、奇数なら 1

    # これ以上の桁は不要
    mod = 1 << (k + 1)
    amod = [a & (mod - 1) for a in A]
    bmod = [b & (mod - 1) for b in B]
    amod.sort()
    bmod.sort()
    ret = 0

    # bmod + amod のうち k ビット目が 1 となる数
    # => (1 << k) 以上 (2 << k) 未満または (3 << k) 以上 (4 << k) 未満
    # しゃくとる
    b01 = bisect.bisect_left(bmod, (1 << k) - amod[0])
    b10 = bisect.bisect_left(bmod, (2 << k) - amod[0])
    b11 = bisect.bisect_left(bmod, (3 << k) - amod[0])
    for a in range(len(amod)):
        while b01 - 1 >= 0 and bmod[b01 - 1] >= (1 << k) - amod[a]:
            b01 -= 1
        while b10 - 1 >= 0 and bmod[b10 - 1] >= (2 << k) - amod[a]:
            b10 -= 1
        while b11 - 1 >= 0 and bmod[b11 - 1] >= (3 << k) - amod[a]:
            b11 -= 1
        # (1 << k) 以上 (2 << k) 未満
        ret += b10 - b01
        # (3 << k) 以上 (4 << k) 未満
        ret += len(bmod) - b11

    return ret % 2


ans = 0
for i in range(30):
    ans += calc_bit(i) * (2 ** i)
print(ans)


Measured memory_bytes: 136520
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

ll mod = 1e9 + 7;
string s[1003];
ll dp[1005][1005];

int main() {
	int H, W; cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> s[i], s[i] += "#";
	s[H] = string(W + 1, '#');
	dp[0][0] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i + 1][j] != '#') dp[i + 1][j] = (dp[i + 1][j] + dp[i][j])%mod;
			if (s[i][j + 1] != '#') dp[i][j + 1] = (dp[i][j + 1] + dp[i][j])%mod;
		}
	}
	cout << dp[H - 1][W - 1] << endl;
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;


int main()
{
	faster
	string s;
	cin>>s;
	int ans=0,a,b,i;
	for(i=0;i<s.size();i++)
	{
		ans+=s[i]-'0';
	}
	//cout<<ans<<nl;
	if(ans%9==0)cout<<"Yes"<<nl;
	else cout<<"No"<<nl;
	return 0;

}


Measured memory_bytes: 3780
import math

n = input()
a = map(float, raw_input().split(" "))
b = map(float, raw_input().split(" "))

p1 = sum([abs(x-y) for x, y in zip(a, b)])
p2 = math.sqrt(sum([(x - y)**2 for x, y in zip(a, b)]))
p3 = math.pow(sum([math.fabs(x - y)**3 for x, y in zip(a, b)]), (1.0/3.0))
p = max([abs(x - y) for x, y in zip(a, b)])

print "%f\n%f\n%f\n%f" % (p1, p2, p3, p)

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


int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> dig(k);
    for(int i=0;i<k;i++){
        cin>>dig[i];
    }
    while(1){
        stringstream ss;
        ss<<n;
        string s=ss.str();
        int same=0;
        for(int i=0;i<s.length();i++){
            for(int j=0;j<k;j++){
                if(s[i]==(dig[j]+'0')){
                        same=1;
                        break;
                }
            }
            if(same)    break;
        }
        if(same)    n++;
        else{
            cout<<n<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var H = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var AB = new (int, int)[M];

        for (int i = 0; i < M; i++)
        {
            var _AB = ReadLine().Split(' ').Select(s => int.Parse(s) - 1).ToArray();
            AB[i] = (_AB[0], _AB[1]);
        }

        var adjacencyList = new List<int>[N + 1];
        for (int i = 0; i < adjacencyList.Length; i++)
        {
            adjacencyList[i] = new List<int>();
        }

        foreach (var (A, B) in AB)
        {
            adjacencyList[A].Add(B);
            adjacencyList[B].Add(A);
        }

        var ans = 0;

        for (int i = 0; i < N; i++)
        {
            var baseH = H[i];
            var ok = true;

            foreach (var v in adjacencyList[i])
            {
                var h = H[v];

                if(baseH <= h)
                {
                    ok = false;
                }
            }

            if(ok)
            {
                ans++;
            }
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 56172
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, k, m;
    cin >> n >> k;
    if(k > (n-1)*(n-2)/2){
        cout << -1 << endl;
        return 0;
    }
    m = n * (n-1) / 2 - k;
    cout << m << endl;
    for(int i=2;i<=n;i++){
        cout << "1 " << i << endl;
        m--;
    }
    int a = 2, b = 3;
    while(m-- > 0){
        cout << a << " " << b << endl;
        if(++b > n) b = ++a + 1;
    }
}


Measured memory_bytes: 256