akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int q; cin >> q;
  vector<int> num(100001);
  rep(i,n) num[a[i]]++;
  ll ans = 0;
  rep(i,n) ans += a[i];
  rep(i,q){
    int b,c; cin >> b >> c;
    num[c] += num[b];
    ans -= (ll)num[b]*b;
    ans += (ll)num[b]*c;
    num[b] = 0;
    cout << ans << endl;
  }
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 200000
typedef pair<i64, i64> P;
i64 N;
priority_queue<P, vector<P>, greater<P>> pq; // <B, A>

void solve() {
  P ba;
  i64 current = 0;
  REP(i, N) {
    ba = pq.top(); pq.pop();
    current += ba.S;
    if (current > ba.F) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main() {
  cin >> N;
  REP(i, N) {
    i64 a, b;
    cin >> a >> b;
    pq.push(mp(b, a));
  }

  solve();

  return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1e9 + 7;




int main() {

	ll a;
	cin >> a;

	string s;
	cin >> s;

	ll ans = 0;

	ans += a * (ll)(s[0] - '0');
	ans *= 100;

	FOR(i, 2, s.size()) {
		if (i == 2) {
			ll cur = a;
			cur *= (ll)(s[i] - '0');
			cur *= 10;
			ans += cur;
		}
		if (i == 3) {
			ll cur = a;
			cur *= (ll)(s[i] - '0');
			ans += cur;
		}
	}
	ans /= 100;
	cout << ans << endl;



}


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

using namespace std;

int main()
{
    string s;
    long long K;
    cin >> s >> K;

    char ans = '1';
    for(int i = 0; i < s.size() && i < K; ++i){
        if(s[i] != '1'){
            ans = s[i];
            break;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
string s;
cin>>s;
if(s.size()==2){
cout << s << endl;}
else{

cout << s.at(2)<<s.at(1)<<s.at(0) << endl;}}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

int n;
ll a[MAXN],f[MAXN][2];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
	    scanf("%lld",&a[i]);
	f[1][0] = a[1];
	f[1][1] = -a[1];
	for(int i = 2;i <= n;i++){
		f[i][0] = max(f[i - 1][0] + a[i],f[i - 1][1] - a[i]);
		f[i][1] = max(f[i - 1][0] - a[i],f[i - 1][1] + a[i]);
	}
	printf("%lld\n",f[n][0]);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,mo=998244353;
int n,i,d[N],cnt[N],ans;
inline int poww(int x,int y){int ans=1;for(;y;y>>=1,x=1ll*x*x%mo)if(y&1)ans=1ll*ans*x%mo;return ans;}
int main(){
	scanf("%d",&n);for(i=1;i<=n;++i)scanf("%d",d+i);if(d[1]!=0){puts("0");return 0;}
	sort(d+1,d+n+1);if(n>1 && d[2]==0){puts("0");return 0;}
	for(i=2;i<=n;++i)if(d[i]>d[i-1]+1){puts("0");return 0;}
	for(i=2;i<=n;++i)++cnt[d[i]];
	ans=1;
	for(i=2;i<=d[n];++i)ans=1ll*ans*poww(cnt[i-1],cnt[i])%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <iostream>


using namespace std;


int main()
{
    int l,r,count=0,d;
    cin>>l>>r>>d;
    for(int i=l;i<=r;++i)
    {
        if(i%d==0)
        {
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(){
  int n, x;
  int l[101];
  int cnt = 1;
  int sum = 0;

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

  for(int i = 1; i <= n; i++){
    scanf("%d", &l[i]);
  }

  for(int i = 1; i <= n; i++){
    sum += l[i];
    if(sum <= x){
      cnt++;
    }else{
      break;
    }
  }

  printf("%d", cnt);
  printf("\n");

}


Measured memory_bytes: 128
n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse
ali, bob = [], []
turn = 'A'
for i in a
  if turn == 'A'
    ali << i
    turn = 'B'
  else
    bob << i
    turn = 'A'
  end
end

puts ali.inject(&:+) - bob.inject(&:+)

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x; cin>>x; if(x>=30) cout << "Yes\n"; else cout << "No\n";

	return 0;
}

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

struct UnionFind
{
	int N;
	vector<int> parent;
	vector<int> size_r;
	int num_of_sets;

	UnionFind(int N) :  N(N), parent(N), size_r(N, 1), num_of_sets(N) {
		for (int i = 0; i < N; ++i) parent[i] = i;
	}

	int root(int x) {
		if (parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size_r[x] < size_r[y]) swap(x, y);
		parent[y] = x;
		size_r[x] += size_r[y];
		size_r[y] = 0;
		num_of_sets--;
		return true;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	int size(int x) {
		return size_r[root(x)];
	}
};

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<int>> g(n);
	UnionFind U(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
		U.merge(a, b);
	}
	vector<vector<int>> block(n);
	for (int i = 0; i < k; i++) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		block[c].push_back(d);
		block[d].push_back(c);
	}
	for (int i = 0; i < n; i++) {
		int ans = U.size(i) - 1;
		ans -= g[i].size();
		for (int e : block[i]) {
			if (U.same(i, e)) ans--;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    int n , res{};
    std :: cin >> n;

    int arr[n];
    for(int i = 0 ; i < n ; i++)
        std :: cin >> arr[i];

    for(int i = 1 ; i < n - 1; i++){
        std :: vector < int > vec;
        for(int j = -1 ; j < 2 ; j++)
            vec.push_back(arr[i + j]);

        std :: sort(vec.begin() , vec.end());
        
        if(vec.at(1) == arr[i])
            res++;
    }

    std :: cout << res << '\n';
}

Measured memory_bytes: 256
import java.io.{BufferedReader, InputStreamReader}

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))

    val n = in.readLine.toInt
    val str = in.readLine
    val memo = Array.ofDim[Int](n, n)
    var max = 0

    (0 until n).foreach { col =>
      val currentCh = str.charAt(col)
      (col + 1 until n).foreach { row =>
        val iterCh = str.charAt(row)
        if (currentCh == iterCh) {
          val point =
            if (col == 0) {
              1
            } else {
              memo(row - 1)(col - 1) + 1
            }
          if (col < row - point + 1) {
            max = Math.max(max, point)
          }
          memo(row)(col) = point
        }
      }
    }
    System.out.println(max)
  }
}

Measured memory_bytes: 149692
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long llint;
typedef pair<int, int> pint;
typedef vector<int> vint;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int A, B, C;
	A = in();
	B = in();
	C = in();
	
	int ans = 0;
	for (int i = 0; i < 40; i++) {
		if (A % 2 || B % 2 || C % 2) break;
		int a = (B + C) / 2;
		int b = (C + A) / 2;
		int c = (A + B) / 2;
		A = a;
		B  =b;
		C = c;
		ans++;
	}
	if (ans > 36) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
#define inf 1000000007

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x/gcd(x,y)*y;
}
 
signed main(){
	int n,cnt=0,tr=0;
	cin>>n;
	bool b[10];
	for(int i=0;i<8;i++)b[i]=false;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(a<400)b[0]=true;
		else if(a<800)b[1]=true;
		else if(a<1200)b[2]=true;
		else if(a<1600)b[3]=true;
		else if(a<2000)b[4]=true;
		else if(a<2400)b[5]=true;
		else if(a<2800)b[6]=true;
		else if(a<3200)b[7]=true;
		else  cnt++;
	}
	for(int i=0;i<8;i++){
		if(b[i])tr++;
	}
	int ma=tr+cnt;
	int mi;
	if(tr==0)mi=1;
	else mi=tr;
	cout<<mi<<" "<<ma<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define MAX 200005
#define MAXV 3000000000
using namespace std;

int main(){
  int n, c, l, r, mid;
  long long a[MAX], min1, min2, max1, max2, ans = MAXV;
  scanf("%d", &n);
  a[0] = 0;
  for(int i = 0; i < n; i++){
    scanf("%d", &c);
    a[i+1] = a[i] + c;
  }
  
  for(int i = 2; i < n-1; i++){
    l = 0; r = i;
    while(r-l > 1){
      mid = (l + r) / 2;
      if(a[mid]*2 - a[i] < 0) l = mid;
      else r = mid;
    }
    if((a[l] + a[r] - a[i])*2 > 0){
      min1 = a[l]; max1 = a[i] - a[l];
    }else{
      min1 = a[i] - a[r]; max1 = a[r];
    }
    
    l = i; r = n;
    while(r-l > 1){
      mid = (l + r) / 2;
      if(a[mid]*2 - a[i] - a[n] < 0) l = mid;
      else r = mid;
    }
    if((a[l] + a[r] - a[i] - a[n])*2 > 0){
      min2 = a[l] - a[i]; max2 = a[n] - a[l];
    }else{
      min2 = a[n] - a[r]; max2 = a[r] - a[i];
    }
    ans = min(ans, max(max1, max2) - min(min1, min2));
  }
  printf("%lld", ans);
}

Measured memory_bytes: 1664
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/




#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int n; cin >> n;
    vector<int> an(30);
    rep(i, n) {
        int x; cin >> x;
        rep(j, 30) {
            if(x & (1<<j)) an[j]++;
        }
    }
    int flg = 0;
    rep(i, 30) {
        if(an[i] & 1) flg = 1;
    }
    if(flg) cout << "No" << endl;
    else cout << "Yes" << endl;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;



int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<ll> > c(w,vector<ll>(h));
    for(int i = h-1; i >= 0; i--){
        for(int j = 0; j < w; j++){
            char tmp;
            cin >> tmp;
            c[j][i] = tmp-'0';
        }
    }

    ll ans = 0;
    for(int i = 0; i < h-1; i++){
        for(int j = 0; j < w; j++){
            // first
            auto d = c;
            ll cnt = 0;
            ll ml = 1;
            d[j].erase(d[j].begin()+i);

            bool changed = true;
            while(changed){
                changed = false;
                for(int l = h-1; l >= 0; l--){
                    ll col = 0;
                    ll num = -1;
                    ll sw = -1;
                    for(int m = 0; m < w; m++){
                        if(d[m].size() < l+1){
                            if(col >= k){
                                for(int p = sw; p < m; p++){
                                    d[p].erase(d[p].begin()+l);
                                }
                                cnt += num*col*ml;
                                changed = true;
                            }
                            col = 0;
                            num = -1;
                            sw = -1;
                            continue;
                        } else {
                            if(d[m][l] == num){
                                col++;
                                continue;
                            } else {
                                if(col >= k){
                                    for(int p = sw; p < m; p++){
                                        d[p].erase(d[p].begin()+l);
                                    }
                                    cnt += num*col*ml;
                                    changed = true;
                                }
                                col = 1;
                                num = d[m][l];
                                sw = m;
                            }
                        }
                    }
                    
                    if(col >= k){
                        for(int p = sw; p < w; p++){
                            d[p].erase(d[p].begin()+l);
                        }
                        cnt += num*col*ml;
                        changed = true;
                    }
                }
                ml *= 2;
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L;
  cin >> N >> L;

  vector<int>apples(N);

  for(int i = 1; i < N+1; i++){
    int tmp = L + i - 1;
    apples[i-1] = tmp;
  }

  int pie = 0;
    for(int i = 0; i < N; i++){
    pie += apples[i];
  }

  int abs_pie = abs(pie);

  int better_pie;
  int judge = 2147483647;
  for(int i = 0; i < N; i++){
    int tmp = apples[i];
    int tmp_pie = pie - tmp;
    int abs_tmp_pie = abs(tmp_pie);
    int sub = abs_pie - abs_tmp_pie;
    int abs_sub = abs(sub);
    if(abs_sub < judge){
      better_pie = tmp_pie;
      judge = abs_sub;
    }
  }

  cout << better_pie << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int A,B;
	cin >> A >> B;
	int C = A + B;
	if (C%2 == 0) {
		cout << C/2 << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    toInt = {"R": 0, "G":1, "B": 2}
    count = [[0, 0, 0] for _ in range(N)]
    count[N-1][toInt[S[N-1]]] += 1
    for i in reversed(range(N-1)):
        for j in range(3): count[i][j] = count[i+1][j]
        count[i][toInt[S[i]]] += 1

    ans = 0
    for i in range(N-2):
        iInt = toInt[S[i]]
        for j in range(i+1, N-1):
            right = {0, 1, 2} - {iInt, toInt[S[j]]}
            if len(right) == 1:
                for key in right:
                    ans += count[j + 1][key]
                    if 2 * j - i < N and toInt[S[2*j - i]] == key: ans -= 1
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 74808
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ans = b[a[0]-1]
for i in range(1,n):
    ans += b[a[i]-1]
    if a[i] - a[i-1] == 1:
        ans += c[a[i-1]-1]
print(ans)


Measured memory_bytes: 3064
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll n , T ; 
    cin >> n >> T ; 
    vector<ll> v(n) ; 
    cin >> v[0] ; 
    ll cur = 0 ; 
    ll L = 0 , R = T ; 
    for(ll i=1;i<n;i++){
    	cin >> v[i] ; 
    	if ( v[i] > L && v[i] <= R ) {
    		R = v[i] + T ; 
    	}
    	else {
    		cur += R - L ; 
    		L = v[i] , R = v[i] + T ;
    	}
    }
    cur += (R - L) ; 
    cout << cur << endl;
    return 0 ;
}


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

int main() {
  int N;
  int A;
  int c1;
  int c2 = 9999;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    c1 = 0;
    while (A%2 == 0){
      A /= 2;
      c1++;
    }
    if (c1 < c2)
      c2 = c1;
  }
    cout << c2 << endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int t,p,r;
	while(cin >> t >> p >> r) {
		if(t==0) break;
		vector<int> acc(t, 0);
		vector<vector<int> > wrong(t,vector<int>(p,0));
		vector<int> pena(t, 0);
		for(int i=0;i<r;i++) {
			int a,b,c;
			string cw;
			cin >> a >> b >> c >> cw;
			a--,b--;
			if(cw=="CORRECT") {
				acc[a]++;
				pena[a] += (c+wrong[a][b]*1200);
			}else if("WRONG") {
				wrong[a][b]++;
			}
		}
		vector<pair<pair<int,int>,int> > ans(t);
		for(int i=0;i<t;i++){
			ans[i] = make_pair(make_pair(-acc[i],pena[i]), i);
		}
		sort(ans.begin(),ans.end());
		for(int i=0;i<t;i++) {
			cout << ans[i].second + 1 << " " << -ans[i].first.first <<  " " << ans[i].first.second << endl;
		}
	}
}


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

long long int countsum(long long int m){
  long long int sum=1;
  if(m==1) return 0; 
  for(long long int i=2;i*i<=m;i++){
    if(i*i==m) sum++;
    else if(m%i==0) sum+=2;
  }
  return sum;
}

bool flag(long long int n,long long int i){
  while(n%i==0) n/=i;
  if((n-1)%i==0) return true;
  else return false;
}

int main(){
  long long int n,m;
  long long sum=1;
  cin >> n;
  m=n-1;
  sum += countsum(m);
  for(long long int i=2;i*i<=n;i++){
    if(i*i==n) sum++;
    else if(n%i==0){
      if(flag(n,i)) sum++;
      // if(flag(n,n-i)) sum++;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		if (N % 2 == 0) {
			System.out.println(N);
		} else {
			System.out.println(N * 2);
		}
	}
}


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

using namespace std;
#define ll long long int


int main()
{
    ll x;
    cin >> x;
    int cnt = 0;
    ll amt = 100;
    while(1){
        amt = amt + amt/100;
        cnt++;
        if(amt>=x) break;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

long long N, X;

long long f(long long a, long long b) {
  if (a == b) return a;
  if (a > b) swap(a, b);
  long long k = (b-1) / a;
  return f(a, b-a*k) + 2*a*k;
}

int main() {
  cin >> N >> X;
  cout << f(X, N-X) + N << "\n";
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    int A; cin >> A;
    if(A%2==0 && (A%3!=0 && A%5!=0)){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
var a,ans:int64;
    q,r,s:char;

begin
  q := 'C';
  r := 'C';
  a := 0;
  ans := 0;
  while not eoln do begin
    read(s);
    if (q='A') and (r='A') then a:=a+1;
    if (q='A') and (r='B') and (s='C') then begin
      q:='B';
      r:='C';
      s:='A';
      ans:=ans+a+1;
    end;
    if (s='C') or ((r='B') and (s<>'C')) or ((r='C') and (s='B')) then a:=0;
    q:=r;
    r:=s;
  end;
  writeln(ans);
end.

Measured memory_bytes: 128
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ull T[100001] = {};
ull A[100001] = {};

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

  ull N;
  cin >> N;

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

  if (T[N - 1] != A[0]) {
    cout << 0 << endl;
    return 0;
  }

  ull ans = 1;
  for (int i = 1; i < N - 1; i++) {
    if (T[i - 1] < T[i] && A[i] > A[i + 1]) {
      if (T[i] != A[i]) {
        cout << 0 << endl;
        return 0;
      }
    } else if (T[i - 1] < T[i] && A[i] == A[i + 1]) {
      if (T[i] > A[i]) {
        cout << 0 << endl;
        return 0;
      }
    } else if (T[i - 1] == T[i] && A[i] > A[i + 1]) {
      if (T[i] < A[i]) {
        cout << 0 << endl;
        return 0;
      }
    } else {
      ans *= min(A[i], T[i]);
      ans %= 1000000007;
    }
  }

/*
  ull ans = 1;
  for (int i = 1; i < N - 1; i++) {
    if (!(T[i - 1] < T[i] || A[i] > A[i + 1])) {
      ans *= min(A[i], T[i]);
      ans %= 1000000007;
    }
  }
  */

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


Measured memory_bytes: 1792
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int m[111][111];
int main()
{
	int mx, my, num;
	scanf("%d%d%d", &mx, &my, &num);
	int px = 0, py = 0;
	for (int i = 0; i < num; i++)
	{
		int t;
		scanf("%d", &t);
		for (int p = 0; p < t; p++)
		{
			m[px][py] = i + 1;
			if (px % 2 == 0)
			{
				if (py == my - 1)px++;
				else py++;
			}
			else
			{
				if (py == 0)px++;
				else py--;
			}
		}
	}
	for (int i = 0; i < mx; i++)
	{
		for (int j = 0; j < my; j++)printf("%d ", m[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n,a,b;
    string s;
    cin>>n>>a>>b>>s;
    int kr = 0;//海外の学生ランキング
    int tu = 0;//予選通過人数
    int gen = a+b;//予選限界通過数
  　char ss[n];
    for(int i = 0;i<n;i++){
       ss[i] = s[i];
    }
    for(int i = 0;i<n;i++){
        bool tuuka = false;
    	if(ss[i] == 'c'){
            //if(tu <gen) tu+= 1;
        }
        if(ss[i] =='b'){
        	 if(tu <gen){
               if(kr <b){
               	tu++;
                kr+=1;
                tuuka = true;
               }
             }
        }
        if(ss[i] == 'a'){
        	if(tu <gen) {
              tu+= 1;
              tuuka = true;
            }
        }
        if(tuuka) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3236
dict_list = {}

N = int(input())

for i in range(N):
	tmp = input()
	if tmp in dict_list.keys():
		dict_list[tmp] += 1
	else:
		dict_list[tmp] = 1

M = int(input())
for i in range(M):
	tmp = input()
	if tmp in dict_list.keys():
		dict_list[tmp] -= 1


answer = max(dict_list.values())
if answer < 0:
	print("0")
else:
	print(answer)

Measured memory_bytes: 3060
#include <cstdio>
using namespace std;
int main(){
	long long num,a,b;
	scanf("%lld %lld %lld",&num,&a,&b);
	if((num>1&&b>=a)||(num==1&&a==b)){
		printf("%lld\n",(num-2)*(b-a)+1);
	}
	else{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define ADD(vertex,length) do{from[len]=(vertex);to[len]=(vertex)+1;val[len]=(length);len++;}while(0)

void run(void){
  int l;
  scanf("%d",&l);
  int from[60];
  int to[60];
  int val[60];
  int len=0;
  int now=1;
  while(l>1){
    ADD(now,0);
    ADD(now,l/2);
    if(l%2!=0){
      from[len]=now;
      to[len]=20;
      val[len]=l-1;
      len++;
    }
    now++;
    l/=2;
  }
  if(now<20){
    from[len]=now;
    to[len]=20;
    val[len]=0;
    len++;
  }
  printf("20 %d\n",len);
  int i;
  for(i=0;i<len;i++){
    printf("%d %d %d\n",from[i],to[i],val[i]);
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 21:46:51 2018

@author: sk
"""


a,b,c,d = map(int, input().split())

s1=a+b
s2=c+d

if s1>s2:
  print("Left")
elif s1==s2:
  print("Balanced")
else:
  print("Right")





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

typedef struct{
  int t[6];
}sDice;

int main(){
  char in[100];
  int i, k;
  sDice d;
  
  for(i=0; i<6; ++i){
    scanf("%d", &d.t[i]);
  }

  scanf("%s", in);

  for(i=0; (unsigned int)i<strlen(in); ++i){
    int work;
    if(in[i] == 'S'){
      work = d.t[5];
      d.t[5] = d.t[1];
      d.t[1] = d.t[0];
      d.t[0] = d.t[4];
      d.t[4] = work;
    }else if(in[i] == 'W'){
      work = d.t[5];
      d.t[5] = d.t[3];
      d.t[3] = d.t[0];
      d.t[0] = d.t[2];
      d.t[2] = work;
    }else if(in[i] == 'N'){
      work = d.t[5];
      d.t[5] = d.t[4];
      d.t[4] = d.t[0];
      d.t[0] = d.t[1];
      d.t[1] = work;
    }else{
      work = d.t[5];
      d.t[5] = d.t[2];
      d.t[2] = d.t[0];
      d.t[0] = d.t[3];
      d.t[3] = work;
    }

  }

  printf("%d\n", d.t[0]);
  
  return 0;
}



Measured memory_bytes: 2724
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll sum = 0;
    rep(i,N)
    {
        ll j = i + 1;
        sum += ((j % 3 != 0) && (j % 5 != 0)) ? j : 0;
    }
    printf("%lld", sum);
}

Measured memory_bytes: 3196
X,K,D = [int(hoge) for hoge in input().split()]
#とりあえず全力でゼロに近づく
X = abs(X)#正ということにする
Risou = X//D#できる限りの移動回数
Amari = X%D #その際にたどり着く座標
if K<=Risou:
    print(X - D*K)
else:#反復横跳び
    Idou = K-Risou
    Idou %= 2
    Amari -= D*Idou
    print(abs(Amari))

Measured memory_bytes: 61676
#include<bits/stdc++.h>
#define re register
#define ui unsigned int
#define ull unsigned long long
int a[250100],p[410];
ui f[410],f1[410],xc[250100],xc1[250100],fac[25010],ifac[25010];
const ui mod=1e9+7;
inline ui add(re ui a,re ui b){return (a+b>mod)?a+b-mod:(a+b);}
inline ui dec(re ui a,re ui b){return (a<b)?a-b+mod:(a-b);}
int main()
{
	re int n,k,m,fr=0,ta=0,nw=1,mx=0;
	re ui ans=1,an1=0,an2=0;
	scanf("%d%d%d",&n,&k,&m);
	for(re int i=1;i<=m;i++)scanf("%d",&a[i]);
	for(re int i=1;i<=n-m;i++)ans=(ull)k*ans%mod;
	fac[0]=ifac[0]=ifac[1]=1;
	for(re int i=2;i<=k;i++)ifac[i]=(ull)(mod-mod/i)*ifac[mod%i]%mod;
	for(re int i=1;i<=k;i++)fac[i]=(ull)i*fac[i-1]%mod,ifac[i]=(ull)ifac[i]*ifac[i-1]%mod;
	ans=(ull)ans*(n-m+1)%mod;
	for(re int i=1;i<=m;i++)
	{
		if(p[a[i]])break;
		p[a[i]]=1;fr++;
	}
	memset(p,0,sizeof(p));
	for(re int i=m;i;i--)
	{
		if(p[a[i]])break;
		p[a[i]]=1;ta++;
	}
	memset(p,0,sizeof(p));
	for(re int i=1;i<=m;i++)
	{
		if(p[a[i]])nw=std::max(nw,p[a[i]]+1);
		p[a[i]]=i;if(i-nw+1>mx)mx=i-nw+1;
	}
	if(mx!=k)
	{
		if(fr!=m)
		{
			f[fr]=1;xc[0]=1;
			for(re int i=1;i<=n-m;i++)
			{
				re ui x1=0;
				for(re int j=k-1;j;j--)x1=add(f[j],x1),f[j]=(x1+(ull)f[j-1]*(k-j+1))%mod;
				for(re int j=1;j<k;j++)xc[i]=add(xc[i],f[j]);
			}
			memset(f,0,sizeof(f));
			f[ta]=1;xc1[0]=1;
			for(re int i=1;i<=n-m;i++)
			{
				re ui x1=0;
				for(re int j=k-1;j;j--)x1=add(f[j],x1),f[j]=(x1+(ull)f[j-1]*(k-j+1))%mod;
				for(re int j=1;j<k;j++)xc1[i]=add(xc1[i],f[j]);
			}
			for(re int i=0;i<=n-m;i++)ans=(ans+(ull)(mod-xc[i])*xc1[n-m-i])%mod;
		}else
		{
			f[0]=1;
			for(re int i=1;i<=n;i++)
			{
				re ui x1=0,x2=0;
				for(re int j=k-1;j;j--)
				{
					x1=add(f[j],x1);x2=add(f1[j],x2);
					f[j]=(x1+(ull)f[j-1]*(k-j+1))%mod;
					f1[j]=(x2+(ull)f1[j-1]*(k-j+1))%mod;
					if(j>=m)f1[j]=add(f1[j],f[j]);
				}
				f[0]=0;
			}
			for(re int i=1;i<k;i++)an1=add(an1,f1[i]);
			ans=(ans+(ull)(mod-an1)*fac[k-m]%mod*ifac[k])%mod;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
int main(){
  ll h,w,ans=0,tmp=0;
  cin>>h>>w;
  ll a=ceil((ld)h/3)*w,b=(h-ceil((ld)h/3))*(w/2),c=(h-ceil((ld)h/3))*(w-w/2);
  ll a2=(h/3)*w,b2=(h-(h/3))*(w/2),c2=(h-(h/3))*(w-w/2);
  tmp=min(max(a,c)-min(a,b),max(a2,c2)-min(a2,b2));
  swap(h,w);
  a=ceil((ld)h/3)*w,b=(h-ceil((ld)h/3))*(w/2),c=(h-ceil((ld)h/3))*(w-w/2);
  a2=(h/3)*w,b2=(h-(h/3))*(w/2),c2=(h-(h/3))*(w-w/2);
  ans=min(max(a,c)-min(a,b),max(a2,c2)-min(a2,b2));
  ans=min(ans,tmp);
  if(h%3==0 ||w%3==0)cout<<"0";
  else cout<<min(ans,min(h,w));
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int n, m;
  while(cin >> n >> m, n || m) {
    vector<vector<int> > G(n);
    FOR(i,0,m) {
      int a, b; cin >> a >> b;
      --a;--b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    int invited[n]; CLR(invited);
    int ans = 0;
    queue<int> Q;
    Q.push(0);
    FOR(i,0,3) {
      queue<int> tmp;
      while(!Q.empty()) {
        int now = Q.front(); Q.pop();
        if(invited[now]) continue;
        invited[now] = true;
        if(now != 0) ans++;
        for(auto &to : G[now]) {
          if(!invited[to]) tmp.push(to);
        }
      }
      while(!tmp.empty()) {
        Q.push(tmp.front());tmp.pop();
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 3268
#include<stdio.h>
int main(){
  int A,B,C;
  scanf("%d %d %d", &A, &B, &C);
  if((A==B && B==C)||((A != B) && (B != C) && (C != A)))
  {
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 1700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x[] = new int[n];
		int y[] = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			y[i] = sc.nextInt();
		}

		System.out.println(getManhattanDistance(n, x, y));
		System.out.println(getEucliDistance2(n, x, y));
		System.out.println(getEucliDistance3(n, x, y));
		System.out.println(getChebyshevDistance(n, x, y));

	}

	static double getManhattanDistance(int n, int x[], int y[]) {
		double sum = 0;
		for (int i = 0; i < n; i++) {
			sum += Math.abs(x[i] - y[i]);
		}

		return sum;
	}

	static double getEucliDistance2(int n, int x[], int y[]) {
		double sum = 0;
		for (int i = 0; i < n; i++) {
			sum += Math.pow(x[i] - y[i], 2);
		}

		return Math.sqrt(sum);
	}

	static double getEucliDistance3(int n, int x[], int y[]) {
		double sum = 0;
		for (int i = 0; i < n; i++) {
			sum += Math.pow(Math.abs(x[i] - y[i]), 3);
		}

		return Math.cbrt(sum);
	}

	static double getChebyshevDistance(int n, int x[], int y[]) {
		double max = Math.abs(x[0] - y[0]);
		for (int i = 1; i < n; i++) {
			if (max < Math.abs(x[i] - y[i])) {
				max = Math.abs(x[i] - y[i]);
			}
		}

		return max;
	}

}

Measured memory_bytes: 26624
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,i,a[500005],sum[500005],ans=0,pw[500005];
const ll mod=1e9+7;
vector<ll>pos[1048576];
ll m(ll a)
{
	if(a>=mod)return a-mod;
	return a;
}
ll calc(ll x,ll v)
{
	if(v==0)return 0;
	ll dp0=1,dp1=1,i,r0,r1;
	for(i=1;i<v;i++)
	{
		r0=dp0;r1=dp1;
		dp0=(r0+r1*(sum[pos[x][i]-1]-sum[pos[x][i-1]]))%mod;
		dp1=(r0+r1*(1LL+sum[pos[x][i]-1]-sum[pos[x][i-1]]))%mod; 
	}
	return dp1;
}
ll calcv(ll x)
{
	ll v;
	v=pos[x].size()-1;
	if(v==0)return 0;
	ll dp0=1,dp1=1,i,r0,r1,dp=1,ans=0;
	ans=(ans+dp*(sum[n-1]-sum[pos[x][0]]))%mod;
	for(i=1;i<v;i++)
	{
		r0=dp0;r1=dp1;
		dp0=(r0+r1*(sum[pos[x][i]-1]-sum[pos[x][i-1]]))%mod;
		dp1=(r0+r1*(1LL+sum[pos[x][i]-1]-sum[pos[x][i-1]]))%mod;
		dp=(r0+r1*(sum[pos[x][i]-1]-sum[pos[x][i-1]]))%mod;
		ans=(ans+dp*(sum[n-1]-sum[pos[x][i]]))%mod;
		//printf("%lld %lld\n",dp,(sum[n-1]-sum[pos[x][i]]));
	}
	return ans;
}
int main()
{
	scanf("%lld",&n);
	pw[0]=1;
	for(i=1;i<=n;i++)pw[i]=pw[i-1]*2%mod;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a[i]^=a[i-1];
		sum[i]=sum[i-1];
		if(a[i]==0)sum[i]++;
	}
	for(i=1;i<=n;i++)pos[a[i]].push_back(i);
	if(a[n]==0)
	{
		ans=1;
		for(i=1;i<1048576;i++)ans=m(ans+calc(i,pos[i].size()));
		if(pos[0].size()>1)ans=(ans+pw[pos[0].size()-1]-1+mod)%mod;
	}
	else
	{
		ans=1;
		ans=(ans+calcv(a[n]))%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 46832
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

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

struct UnionFind{
    vector<int> parents;
    vector<int> rank;
    UnionFind(int n){
        parents.resize(n);
        rank.assign(n, 1);
        REP(i, n){
            parents[i] = i;
        }
    }
    int find(int x){
        if(parents[x] == x) return x;
        return parents[x] = find(parents[x]);
    }
    
    int unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return -1;
        if(rank[x] > rank[y]) parents[y] = x;
        else{
            parents[x] = y;
            if(rank[x]==rank[y]) rank[y]++;
        }
        return 0;
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int N,K,L;
unordered_map<int, unordered_map<int, int> > cnt;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> K >> L;
    UnionFind uf1(N);
    UnionFind uf2(N);
    REP(i,K){
        int p,q;
        cin >> p >> q;
        p--;q--;
        uf1.unite(p,q);
    }
    REP(i,L) {
        int r,s;
        cin >> r >> s;
        r--;s--;
        uf2.unite(r,s);
    }
    REP(i,N) cnt[uf1.find(i)][uf2.find(i)]++;
    REP(i,N-1) cout << cnt[uf1.find(i)][uf2.find(i)] << " ";
    cout << cnt[uf1.find(N-1)][uf2.find(N-1)] << endl;
    return 0;
}

Measured memory_bytes: 31304
#include <iostream>

int inverse(int n, int res = 0) {
	return n == 0 ? res : inverse(n / 10, res * 10 + n % 10);
}
bool is_palindrom(int n) {
	return n == inverse(n);
}

int main(){
	int a, b;
	std::cin >> a >> b;
	int res = 0;
	for (; a <= b; ++a) {
		if (is_palindrom(a)) ++res;
	}
	std::cout << res << std::endl;
}

Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <cstdio>

using namespace std;

typedef pair<double, double> Point;

const double EPS = 1e-8;

double cross(Point a, Point b){
  return a.first * b.second - a.second * b.first;
}

double dist(Point a, Point b){
  return (a.first - b.first) * (a.first - b.first) - (a.second - b.second) * (a.second - b.second);
}

bool isParallel(Point a, Point b){
  return abs(cross(a, b)) < EPS;
}

int n;
vector<Point> input;
Point ans;

bool solve(){
  if(input.size() % 2) return false;
  bool f = true;
  for(int i=0;i<input.size()/2;i++){
    Point a1 = input[i+1];
    Point a2 = input[i];
    Point b1 = input[(input.size()/2+i+1)%input.size()];
    Point b2 = input[input.size()/2+i];
    if(!isParallel(Point(a1.first-a2.first, a1.second-a2.second), 
                   Point(b1.first-b2.first, b1.second-b2.second))) return false;
    if(abs(dist(a1, a2) - dist(b1, b2)) >= EPS) return false;
  }
  Point a = input[0];
  Point b = input[input.size()/2];
  /*long double tmp = 0.0;
  if(abs(a.first + b.first) < EPS) tmp = 333.0;
  if(abs(a.second + b.second) < EPS) tmp = 333.0;
  ans = Point((a.first+tmp + b.first+tmp) / 2.0, (a.second+tmp + b.second+tmp) / 2.0);
  ans.first -= tmp;
  ans.second -= tmp;*/
  ans = Point((a.first + b.first) / 2.0, (a.second + b.second) / 2.0);
  return true;
}

main(){
  cin >> n;
  for(int i=0;i<n;i++){
    Point in;
    cin >> in.first >> in.second;
    input.push_back(in);
  }
  if(!solve()) printf("NA\n");
  else printf("%.8f %.8f\n", ans.first, ans.second);
}

Measured memory_bytes: 1252
#include <stdio.h>
#include <algorithm>
#include <functional>

using namespace std;

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

int main() {
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);

    int h[N];
    REP(i, N) {
        scanf("%d", &h[i]);
    }

    sort(h, h + N, greater<int>());

    long low = 0;
    long high = 1e9;
    long T = 0;
    long temp = 0;
    while (abs(high - low) > 1) {
        T = (low + high) / 2;

        temp = 0;
        REP(i, N) {
            long hi = h[i] - (B * T);
            if (hi > 0) {
                temp += hi / (A - B);
                temp += ((hi % (A - B)) == 0) ? 0 : 1;
            }
        }

        // printf("temp = %ld, T = %ld, high = %d, low = %d\n", temp, T, high, low);
        if (temp <= T) {
            high = T;
        } else {
            low = T;
        }
    }

    printf("%ld\n", high);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=1;i<=n;i++){
        int ans = 0;
        for (int x=1;x<=(int)sqrt(i);x++){
            for(int y=1;y<=x;y++){
                for(int z=1;z<=y;z++){
                    if (x*x+y*y+z*z+x*y+y*z+z*x == i){
                    if (x == y && y == z) ans ++;
                    else if(x!=y&&y!=z&&z!=x)ans += 6;
                    else ans += 3;
                    }
                }
            }
        }
    cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3688
import Text.Printf

rnd x = (fromIntegral $ round $ x * 1000) / 1000

-- ax+by=c
-- dx+ey=f
-- ->
-- ax+b(f-dx)/e=c  -> (ae-bd)x=ce-bf
ans :: (Double,Double,Double) -> (Double,Double,Double) -> (Double,Double)
ans (a,b,c) (d,e,f) =
    let x = (c*e-b*f) / (a*e-b*d)
        y = (c-a*x) / b
        x' = rnd x
        y' = rnd y
    in
      (x',y')

main = do
  c <- getContents
  let t = map (map read) $ map words $ lines c :: [[Double]]
      i = map (\(a:b:c:d:e:f:xs) -> [(a,b,c), (d,e,f)]) t
      o = map (\(f1:f2:fs) -> ans f1 f2) i
  mapM_ (\(x,y) -> printf "%.3f %.3f\n" x y) o

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

#define int long long

int log2l(int t) {
	for (int i = 60; ~i; i--) {
		if (t & (1ll << i)) return i;
	}
	return 0;
}

int32_t main() {
	int l, r;
	cin >> l >> r;
	if (l == r) {
		cout << 1;
		return 0;
	}
	while (l >= (1ll << (int)floor(log2l(r)))) {
		l -= 1ll << (int)floor(log2l(r));
		r -= 1ll << (int)floor(log2l(r));
	}
	int d = floor(log2l(r));
	int t = r - (1ll << d);
	int ans = 0;
	if (t == 0) ans = 1;
	else ans = 1ll << (int)(floor(log2l(t) + 1));
//	cout << ans << ' ' << t << ' ' << r << ' ' << (1ll << d) << ' ' << d << endl;
	int x = (1ll << d) - l;
	ans += x;
//	cout << ans << endl;
	if (t == 0) ans += (1ll << d) - max(l, 1ll);
	else ans += (1ll << d) - max(l, 1ll << (int)(floor(log2l(t) + 1)));
	cout << ans;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<set>
//#include<math.h>
//#include<queue>
//#include<iostream>
using namespace std;

int n;
#define maxn 100011
char s[maxn];

int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	int i;for (i=(n+3)>>1;i<=n;i++) if (s[i]!=s[n-i+1] || s[i]!=s[i-1]) break;
	printf("%d\n",i-1);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int solve(int,int);
int n,q,i,j;
int a[2000],m[2000];
int main(){
  int h;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }
  for(i=0;i<q;i++){
    h=solve(0,m[i]);
    if(h==1){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;
}
int solve(int c,int b){
  int res;
  if(b==0){
    return 1;
  }
  if(c>=n){
    return 0;
  }
  res=solve(c+1,b) || solve(c+1,b-a[c]);
  return res;
}


Measured memory_bytes: 2076