akhauriyash/Code-Regression huggingface dataset:
//bad_bat
#include<bits/stdc++.h>
using namespace std;

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007
#define tc             ll tc;scanf("%lld",&tc);while(tc--)

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

int main()
{

    ll n;
    cin >> n;
    ll ans=0;
    vector<ll> a,b,c;
    for(ll i=0;i<n;i++)
    {

        ll x;
        cin >> x;
        a.pb(x);
    }
    for(ll i=0;i<n;i++)
    {

        ll x;
        cin >> x;
        ans+=x;
    }
    ll pre=-1;
    for(ll i=0;i<n-1;i++)
    {

        ll x;
        cin >> x;
        c.pb(x);
    }
    for(ll i=0;i<a.size();i++)
    {

        ll x=a[i];
        if(pre==x-1 && pre!=-1) ans+=c[pre-1];
        pre=x;
    }
    cout << ans;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define mkp make_pair
#define pb push_back
const ll INF=4e18;
const ll MAX=1e6+5;
const ll MOD=1e9+7;
//}}}
vector<int> v;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,x;
	cin>>n;
	cin>>x;
	v.pb(x);
	for(int i=1;i<n;i++){
		cin>>x;
		if(x!=v.back())
			v.emplace_back(x);
	}
	int si=SZ(v);
	debug(si);
	v.pb(MAX);
	int now,w=0;
	int ans=0;
	for(int i=0;i<si;i++){
		if(w==0){
			ans++;
			if(v[i+1]>v[i])	w=1;
			else 			w=-1;
			now=v[i];
		}
		else{
			if(w==1)	if(v[i]<now)	w=0;
			if(w==-1)	if(v[i]>now)	w=0;
			now=v[i];
			if(!w)	i--;
		}
	}
	cout<<ans<< '\n';
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define B bitset<500>
using namespace std;
int n,m,x,cnt;
int lis[200001],st[200001],ed[200001];
bool die[2001];
B a[2001];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{ 
	//	scanf("%d",&x);
		x=2;
		st[i]=cnt+1;
		for(int j=1;j<=x;j++)
			scanf("%d",&lis[++cnt]);
		ed[i]=cnt;
	} 
	for(int i=1;i<=n;i++)
	{
		a[i][i]=1;
		for(int j=m;j;j--)
		{
			int sum=0;
			for(int k=st[j];k<=ed[j];k++)
			if(a[i][lis[k]]) ++sum;
			if(sum>1)
			{
				die[i]=1;
				break;
			}
			else
			if(sum==1)
				for(int k=st[j];k<=ed[j];k++)
					a[i][lis[k]]=1;
		}
	}
	int ans=0;
	for(int i=1;i<n;i++)
	if(!die[i])
		for(int j=i+1;j<=n;j++)
		if(!die[j] && (a[i]&a[j]).none())
			++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
 
double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}
 
std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}
 
std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}
 
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
 
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
 
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
const int mod = 1000000007;
 
 
int main() {
    double r;
    cin >> r;
 
    printf("%.20f\n", r * 2 * PI);
}

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n, k, c=0, a[1000]={};
    cin>>n>>k;
    for(int z=0;z<n;z++){
        cin>>a[z];
    }
    sort(a,a+n);
    for(int z=0;z<k;z++){
        c+=a[z];
    }
    cout<<c<<endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int solve(int price, vector<int> coins)
{
  vector<int> dp(price + 5, INF);
  int n = coins.size();
  dp[0] = 0;
  for (int p = 1; p <= price; ++p) {
    for (int i = 0; i < n; ++i) {
      if (coins[i] <= p) {
        dp[p] = min(dp[p], dp[p - coins[i]] + 1);
      }
    }
  }
  return dp[price];
}

int main()
{
  int price = 0, kinds = 0;
  fscanf(stdin, "%d %d", &price, &kinds);
  vector<int> coins(kinds, 0);
  for (int i = 0; i < kinds; ++i) {
    fscanf(stdin, "%d", &coins[i]);
  }
  sort(coins.begin(), coins.end());
  int ans = solve(price, coins);
  fprintf(stdout, "%d", ans);
  fprintf(stdout, "\n");
  return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    cout << string(tx - sx, 'R');
    cout << string(ty - sy, 'U');
    cout << string(tx - sx, 'L');
    cout << string(ty - sy, 'D');
    
    cout << "D";
    sy--, tx++;
    cout << string(tx - sx, 'R');
    cout << string(ty - sy, 'U');
    cout << "L";

    cout << "U";
    sy++, tx--;
    sx--, ty++;
    cout << string(tx - sx, 'L');
    cout << string(ty - sy, 'D');
    cout << "R";
    cout << endl;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    string s;
    cin >>s;
    ll sum=0;
    F0R(i,s.length())
    {
      if(s[i] == '-') sum--;
      else sum++;
    }
    cout << sum << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
import sys


k = 'abcdefghijklmnopqrstuvwxyz'
alp = {}

for i in k:
    alp[i] = 0


s = input()

for i in s:
    if alp[i] == 0:
        alp[i] = 1
    else:
        print('no')
        sys.exit()

print('yes')


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

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};


vector<int> edge[200010];
int parent[200010];
int child[200010];

int dfs(int from, int par) {
	int ret = 0;
	for(int to : edge[from]) {
		if(to == par) continue;
		parent[to] = from;
		ret += dfs(to, from);
	}
	return child[from] = ret + 1;
}

const int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
int main() {
	int n; cin >> n;
	for(int i = 0; i < n - 1; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	parent[0] = -1;
	dfs(0, -1);
	mint ans = 0;
	for(int i = 0; i < n; ++i) {
		mint x = 1;
		mint y = 1;
		for(int j : edge[i]) {
			mint p = 2;
			if(parent[j] == i) {
				p = (mint)1 / p.pow(child[j]);
			} else {
				p = (mint)1 / p.pow(n - child[i]);
			}
			x *= p;
			y += (mint)1 / p - 1;
		}
		ans += ((mint)1 - x * y) / 2;
		cerr << ((mint)1 - x * y) / 2 << '\n';
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 21632
def solve(pos0_is_sheep, pos1_is_sheep):
    pre_is_sheep = pos1_is_sheep
    prepre_is_sheep = pos0_is_sheep
    ans = [pos0_is_sheep]
    for is_same_neighbors in s[1:]:
        ans.append(pre_is_sheep)
        if pre_is_sheep:
            pre_is_sheep = is_same_neighbors == prepre_is_sheep
            prepre_is_sheep = True
        else:
            pre_is_sheep = is_same_neighbors != prepre_is_sheep
            prepre_is_sheep = False
    if pos0_is_sheep != pre_is_sheep:
        return False
    if pos0_is_sheep and s[0] != (prepre_is_sheep == pos1_is_sheep):
        return False
    if not pos0_is_sheep and s[0] == (prepre_is_sheep == pos1_is_sheep):
        return False
    return ans


n = int(input())
s = [c == 'o' for c in input().strip()]

for pos0_is_sheep, pos1_is_sheep in ((1, 1), (1, 0), (0, 1), (0, 0)):
    result = solve(pos0_is_sheep, pos1_is_sheep)
    if result:
        print(''.join('WS'[is_sheep] for is_sheep in result))
        break
else:
    print(-1)


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

const ll mod = 1000000007;
const ll INF = 1001001001;

int main(){
    int n; cin >> n;
    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        ans[a - 1] = i + 1;
    }
    for(int i = 0; i < n; i++) cout << ans[i] << " ";
}


Measured memory_bytes: 3752
import sys

r,g,b = input().split()

if 1 > int(r) or 1 > int(g) or 1 > int(b) or 9 < int(r) or 9 < int(g) or 9 < int(b):
    sys.exit()

if int(r + g + b)%4 == 0:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>

using namespace std;

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

int N;
ll K, a[200100];

map<ll, ll> zip;  //圧縮前の座標、圧縮後の座標

int compress(vector<ll> &x){
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    for(int i = 0; i < x.size(); i++){
        zip[x[i]] = i;
    }
    return (int)x.size();
}

#define MAX_N 200000

ll bit[MAX_N+1];

void init(int n){
    for(int i = 0; i < n; i++){
        bit[i] = 0;
    }
}

// indexが0~iまでの和を求める。
ll sum(int i){
    ll s = 0;
    while(i > 0){
        s += bit[i];
        i -= i & (-i);
    }
    return s;
}

// iがindex, xが加える値, nが全体の配列の大きさ
void add(int i, ll x, int n){
    while(i <= n){
        bit[i] += x;
        i += i & (-i);
    }
}

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

    a[0] = 0;
    vector<ll> x;
    ll xx;
    for(int i = 0; i < N; i++){
        cin >> xx;
        a[i+1] = a[i] + (xx - K);
    }
    for(int i = 0; i <= N; i++){
        x.push_back(a[i]);
    }

    int n = compress(x);
    for(int i = 0; i <= N; i++){
        a[i] = zip[a[i]];
    }


    init(n+1);
    ll res = 0;
    for(int i = 0; i <= N; i++){
        res += sum(a[i]+1);
        add(a[i]+1, 1LL, n+1);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 17392
s = input()
t = input()

s1 = "".join(sorted(s))
t1 = "".join(sorted(t, reverse=True))

d = [s1, t1]
d = sorted(d)
if s1 == t1:
    print("No")
elif d[0] == s1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
using System;
namespace kozaiyApp
{
    public class DKnapsack1
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int Knapsack = int.Parse(input[1]);

            long[] W = new long[N];
            long[] V = new long[N];

            for (int i = 0; i < N; i++)
            {
                string[] inputData = Console.ReadLine().Split(' ');
                W[i] = long.Parse(inputData[0]);
                V[i] = long.Parse(inputData[1]);
            }

            long[,] DP = new long[N + 1, Knapsack + 1];

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= Knapsack; j++)
                {
                    if (i == 0)
                    {
                        DP[i, j] = 0;
                    }
                    else if (W[i - 1] > j)
                    {
                        DP[i, j] = DP[i - 1, j];
                    }
                    else
                    {
                        DP[i, j] = Math.Max(DP[i - 1, j], V[i - 1] + DP[i - 1, j - W[i - 1]]);
                    }
                }
            }

            Console.WriteLine(DP[N, Knapsack]);
        }
    }
}


Measured memory_bytes: 88800
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int[][] field = new int[h + 2][w + 2];
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                field[i][j] = sc.nextInt();
            }
        }
        search(0, 0, field);
        long count = 0;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (field[i][j] == 1) {
                    if (field[i - 1][j] == -1) {
                        count++;
                    }
                    if (field[i][j - 1] == -1) {
                        count++;
                    }
                    if (field[i][j + 1] == -1) {
                        count++;
                    }
                    if (field[i + 1][j] == -1) {
                        count++;
                    }
                    if (i % 2 == 1) {
                        if (field[i - 1][j + 1] == -1) {
                            count++;
                        }
                        if (field[i + 1][j + 1] == -1) {
                            count++;
                        }
                    } else {
                        if (field[i - 1][j - 1] == -1) {
                            count++;
                        }
                        if (field[i + 1][j - 1] == -1) {
                            count++;
                        }
                    }
                }
            }
        }
        System.out.println(count);
    }
    
    static void search(int hh, int ww, int[][]field) {
        if (hh < 0 || hh >= field.length || ww < 0 || ww >= field[hh].length) {
            return;
        }
        if (field[hh][ww] != 0) {
            return;
        }
        field[hh][ww] = -1;
        search(hh - 1, ww, field);
        search(hh, ww - 1,  field);
        search(hh, ww + 1, field);
        search(hh + 1, ww, field);
        if (hh % 2 == 1) {
            search(hh - 1, ww + 1, field);
            search(hh + 1, ww + 1, field);
        } else {
            search(hh - 1, ww - 1, field);
            search(hh + 1, ww - 1, field);
        }
    }
}



Measured memory_bytes: 38680
#include <bits/stdc++.h>
using namespace std;
struct answer{int x1,y1,x2,y2;};
int main(){
	int h,w;
	cin>>h>>w;
	int coin[h+2][w+2]={};
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>coin[i][j];
			coin[i][j]%=2;
		}
	}
	vector<int> x1,y1,x2,y2;
	int x=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<w;j++){
			if(coin[i][j]==1){
				x1.push_back(i);
				y1.push_back(j);
				x2.push_back(i);
				y2.push_back(j+1);
				x++;
			}
			coin[i][j+1]=(coin[i][j]+coin[i][j+1])%2;
		}
	}
	for(int i=1;i<h;i++){
		if(coin[i][w]==1){
			x1.push_back(i);
			y1.push_back(w);
			x2.push_back(i+1);
			y2.push_back(w);
			x++;
		}
		coin[i+1][w]=(coin[i][w]+coin[i+1][w])%2;
	}
	cout<<x<<endl;
	for(int i=0;i<x;i++){
		cout<<x1[i]<<" "<<y1[i]<<" "<<x2[i]<<" "<<y2[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 5220
from sys import stdin
N = int(stdin.readline().rstrip())

ans = 0
count = {}

for i in map(str, range(1, N+1)):
    first = i[0]
    last = i[-1]
    key = first + last
    if "0" not in key:
        count[key] = count.get(key, 0) + 1

for key, value in count.items():
    new_key = key[-1] + key[0]
    ans += value * count.get(new_key, 0)

print(ans)

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

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

	int min;
	cin >> min;

	int ret = -1000000000;
	for (int i = 1; i < n; ++i) {
		int t;
		cin >> t;

		int diff = t - min;
		if (ret < diff) {
			ret = diff;
		}

		if (t < min) {
			min = t;
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,int b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,ti);
    laz.clear();
    laz.resize(2*n-1,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
  void update(int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<Int,Int> ch(n,
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  0,0,
			  [](Int a,Int b){return a*b;});
  ch.build(n,vector<Int>(n,0));
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>s>>t>>x;
      ch.update(s-1,t,x);
    }
  }
}

/*
  verified on 2018/03/04
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G
*/



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

main(){
int N;
cin >> N;
int n[4];
for(int ii=0;ii<4;ii++){
n[ii]=N%10;
N/=10;
}
int ans=0;
for(int ii=0; ii<4;ii++){
if(n[ii]==2)ans++;
}
cout << ans << endl;
}

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

/*
   AtCoder contest
   coder : yoichidon
 */


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double T = sc.nextInt();
        double X = sc.nextInt();
        System.out.println(T/X);
    }
}


Measured memory_bytes: 23892
def is_square(n):
    return n % (n**0.5) == 0

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

n = int(input())
if is_square(n): print(int(n**0.5*2-2))
else:
    res = make_divisors(n)
    print(res[len(res)//2-1]+res[len(res)//2]-2)

Measured memory_bytes: 3268
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	d := make(map[int]int)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		if _, ok := d[a-1]; ok {
			d[a-1]++
		} else {
			d[a-1] = 1
		}
		if _, ok := d[b-1]; ok {
			d[b-1]++
		} else {
			d[b-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		fmt.Println(d[i])
	}
}



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

using namespace std; 



int main () {
int k; 
string s; 

cin >> k >> s; 

if (s.length() <= k ) {
  cout << s; 
}
else if (s.length() != k) {
  cout << s.substr(0, k) << "..."; 
}

}

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

using namespace std;

int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double d = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
    cout << setprecision(10) << d << "\n"; 
    return 0;   
}



Measured memory_bytes: 3292
N,H=map(int,input().split())
S=[[int(x) for x in input().split()] for _ in range(N)]
A,B=zip(*S)
A=max(A)
B=[b for b in B if b>A]
B.sort(reverse=True)
ans=0
cnt=0
for b in B:
    if H<=0:
        break
    cnt+=1
    H-=b
if H>0:
    cnt+=(H-1)//A+1
print(cnt)

Measured memory_bytes: 73304
N = int(input())
v_array = [int(i) for i in input().split()]

for i in range(N-1):
    now_min = v_array[i]
    min_index = i
    for j in range(i+1,N):
        if v_array[j] < now_min:
            min_index = j
            now_min = v_array[j]
    if min_index != i:
        v_array.pop(min_index)
        v_array.insert(min_index,v_array[i])
        v_array.pop(i)
        v_array.insert(i, now_min)

synthesis = v_array[0]

for i in range(1,N):
    synthesis = (synthesis + v_array[i]) / 2

print(synthesis)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
int main()
{
	long long a;
	cin>>a;
	long long i=0;
	for (;;i++)
	{
		if (pow(2,i)<=a&&pow(2,i+1)>a) break;
	}
	unsigned long long ans=pow(2,i+1)-1;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

class UnionFind{
public:
	vector<int> par;
	//0-indexed
	UnionFind(int n){init(n);}
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		else par[x] = y;
	}
	bool same(int x,int y){
		return root(x)==root(y);
	}
};


// なもりグラフ
// https://www.hamayanhamayan.com/entry/2019/08/25/090415

int main(){
	int N,H,W;
	ll ans = 0;
	cin >> N >> H >> W;
	UnionFind uf(H+W+6);
	priority_queue< pair<ll,P> > pq;
	FOR(i,0,N){
		int r,c,a;
		cin >> r >> c >> a;
		pq.push({a,{r,c}});
	}
	FOR(i,0,N){
		auto X = pq.top();
		int h = X.second.first;
		int w = X.second.second;
		int a = X.first;
		pq.pop();
		if(not uf.same(h,w+H)){
			ans += a;
			uf.unite(h,w+H);
		}else if(not uf.same(h,H+W+2)){
			ans += a;
			uf.unite(h,H+W+2);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end()) //vector
int n,arr[100005],dp[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    dp[0]=0;dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    }
    // for(int i=0;i<n;i++) cout<<dp[i]<<" ";
    // cout<<endl;
    cout<<dp[n-1]<<endl; 
}

Measured memory_bytes: 1024
def bb
    n = gets.chomp.to_i

    w = []
    for i in 1..n
        w.push(gets.chomp)
    end

    unless w.length == w.uniq.length
        puts 'No'
        exit
    end

    for i in 1..(n-1)
        unless w[i-1][-1] == w[i][0]
            puts 'No'
            exit
        end
    end

    puts 'Yes'
end

bb

Measured memory_bytes: 3836
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())

    primes = defaultdict(int)
    for n in range(2, N + 1):
        tmp = n
        if n == 2:
            primes[2] += 1
            continue

        for i in range(2, int(n ** 0.5) + 1):
            if tmp % i == 0:
                cnt = 0
                while tmp % i == 0:
                    cnt += 1
                    tmp //= i
                primes[i] += cnt

        if tmp != 1:
            primes[tmp] += 1

    ans = 1
    for k, v in primes.items():
        ans *= v + 1
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc119a
{
    class Program
    {
        static void Main(string[] args)
        {
            if(int.Parse(Console.ReadLine().Split('/')[1]) < 5)
            {
                Console.WriteLine("Heisei");
            }
            else
            {
                Console.WriteLine("TBD");
            }

#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
    }
}


Measured memory_bytes: 11092
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN       PIC X(3).
01 a        PIC 9(1).
01 b        PIC 9(1).
01 n        PIC 9(1).
01 i        PIC 9(2).
01 ans      PIC X(9).

PROCEDURE DIVISION.
  ACCEPT LN.
  UNSTRING LN DELIMITED BY SPACE INTO a b.
  IF a < b
    MOVE b TO n
  ELSE
    MOVE a TO n
    MOVE b TO a
  END-IF.
  PERFORM VARYING i FROM 1 BY 1 UNTIL n < i
    MOVE a TO ans(i:1)
  END-PERFORM.
  DISPLAY ans(1:n).
  STOP RUN.


Measured memory_bytes: 892
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	Scanner in = new Scanner(System.in);
	HashMap<String, String[]> hash = new HashMap<String, String[]>();
	HashSet<String> ans = new HashSet<String>(), registered = new HashSet<String>();
	int n;
	
	void makeHashSet(String target) {
		String[] groupMem = hash.get(target);
		for (int i = 0; i < groupMem.length; i++) {
			String nextMem = groupMem[i];
			if (nextMem == null) break;
			if (hash.containsKey(nextMem)) {
				if (!registered.contains(nextMem)) {
					registered.add(nextMem);
					makeHashSet(nextMem);
				}
			} else {
				ans.add(nextMem);
			}
		}
	}
	
	public void run() {
		while (true) {
			String target = "";
			n = in.nextInt();
			if (n == 0) break;
			ans.clear(); hash.clear(); registered.clear();
			for (int i = 0; i < n; i++) {
				String s = in.next();
				s = s.replace(':', ' ');
				s = s.replace(',', ' ');
				s = s.replace('.', ' ');
				StringTokenizer st = new StringTokenizer(s);
				String groupName = st.nextToken();
				if (i == 0) target = groupName.toString();
				String[] member = new String[100];
				for (int j = 0; st.hasMoreElements(); j++) {
					String nextMember = st.nextToken();
					member[j] = nextMember.toString();
				}
				hash.put(groupName, member);
			}
			
			makeHashSet(target);
			System.out.println(ans.size());
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

long long solve(long long h)
{
    if (h == 1)
    {
        return 1;
    }
    else
    {
        return 1 + 2 * solve(h / 2);
    }
}

int main()
{
    long long h;
    cin >> h;
    cout << solve(h) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
ll solve(const vector<ll>& A) {
    const ll n = A.size();
    if (n == 1) return A[0];
    vector<ll> S = A;
    rep(i, 1, n) S[i] += S[i-1];
    if (A[n-1] >= S[n-2]) return A[n-1];
    ll res = (S[n-1]+1)/2;
    map<ll, ll> cnt;
    rep(i, n) cnt[A[i]]++;
    if (cnt.size() * S[n-1] >= ll(1e9)) return res;
    vector<ll> dp(S[n-1]+1, -1); dp[0] = 0;
    each(p, cnt) {
        ll x, m; tie(x, m) = p;
        vector<ll> ndp = dp;
        each(i, ndp) if (i >= 0) i = m;
        rep(i, ndp.size()) {
            if (ndp[i] <= 0) continue;
            if (i + x < ndp.size()) chmax(ndp[i+x], ndp[i]-1);
        }
        dp = ndp;
    }
    rep(i, res, dp.size()) if (dp[i] >= 0) return i;
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> A(n); cin >> A;
    sort(all(A));
    // vector<ll> S = A;
    // rep(i, 1, n) S[i] += S[i-1];
    // vector<ll> a;
    // rep(i, 1, 1<<n) {
    //     ll sum = 0;
    //     rep(j, n) if (i>>j & 1) sum += A[j];
    //     a.pb(sum);
    // }
    // sort(all(a));
    // cout << S << endl;
    // cout << a << endl;
    // cout << a[a.size()/2] << endl;
    cout << solve(A) << endl;
}


Measured memory_bytes: 62848
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX_W 10000
#define INF 10000000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N, M;
int A[MAX_N], B[MAX_N];

int main(void)
{
  cin >> N >> M;
  vector<vector<int>> jobs(M);
  REP(i, N)
  {
    int a, b;
    cin >> a >> b;
    if (a > M) continue;
    jobs[M - a].push_back(b);
  }

  priority_queue<int> q;
  ll ans = 0;
  for (int i = M - 1; i >= 0; i--) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5632
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

struct Info{
	Info(int arg_row,int arg_col,int arg_dist){
		row = arg_row;
		col = arg_col;
		dist = arg_dist;
	}
	Info(){
		row = 0,col = 0,dist = 0;
	}

	int row,col,dist;
};

int H,W,div_row[4] = {-1,0,0,1},div_col[4] = {0,-1,1,0};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

int main(){

	int escape_row,escape_col;
	scanf("%d %d",&H,&W);
	char map[200][201];

	int distance[200][200];

	for(int i = 0; i < H; i++){
		scanf("%s",map[i]);
		for(int k = 0; k < W;k++){
			distance[i][k] = -1;
			if(map[i][k] == '%'){
				escape_row = i;
				escape_col = k;
			}
		}
	}

	distance[escape_row][escape_col] = 0;

	int prin = -1,enemy = 50000;

	queue<Info> Q;

	Q.push(Info(escape_row,escape_col,0));
	Info current;

	while(!Q.empty()){
		current = Q.front();
		Q.pop();

		if(map[current.row][current.col] == '@'){
			if(prin == -1){
				prin = current.dist;
			}else{
				prin = min(prin,current.dist);
			}
			continue;
		}else if(map[current.row][current.col] == '$'){
			enemy = min(enemy,current.dist);
			continue;
		}

		if((prin != -1 && current.dist >= prin) || (current.dist >= enemy))continue;

		for(int i = 0; i < 4; i++){
			if(rangeCheck(current.row+div_row[i],current.col+div_col[i]) == true && map[current.row+div_row[i]][current.col+div_col[i]] != '#' &&
					(distance[current.row+div_row[i]][current.col+div_col[i]] == -1 || distance[current.row+div_row[i]][current.col+div_col[i]] > current.dist+1)){
				distance[current.row+div_row[i]][current.col+div_col[i]] = current.dist+1;
				Q.push(Info(current.row+div_row[i],current.col+div_col[i],current.dist+1));
			}
		}
	}

	if(prin == -1 || prin >= enemy){
		printf("No\n");
	}else{
		printf("Yes\n");
	}

    return 0;
}

Measured memory_bytes: 2872
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    ll n = s.size();

    vector<ll> a(n);
    for(ll i=0;i<n;++i){
        a[i] = s[i] - '0';
    }

    ll ans = 0;
    for(ll bit=0;bit<(1<<n-1);++bit){
        ll num = a[0];
        ll sum = 0;
        for(ll i=0;i<n-1;++i){
            if(bit >> i & 1){
                sum += num;
                num = a[i+1];
            }else{
                num *= 10;
                num += a[i+1];
            }
        }
        if(num != a[n-1]){
            sum += num;
        }else{
            sum += a[n-1];
        }
        //cout<<sum<<endl;
        ans += sum;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <algorithm>
typedef long long ll;
#define MAXN (int(2e5))
using namespace std;

int main(int argc,char ** argv)
{
    int n;
    cin>>n;
    int a[MAXN];
    for(int i=0;i<n;++i)cin>>a[i];
    ll cache=0,ans=0;
    int r=0;
    for(int i=0;i<n;++i){
        while(r<n){
            if(cache+a[r]!=(cache^a[r]))
                break;
            cache+=a[r];
            ++r;
        }
        ans+=r-i;
        cache-=a[i];
    }
    cout<<ans<<endl;
    //system("pause > nul");
    return 0;
}

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

int main() {
  	int N, min, max, a;
    cin >> N;
    for (int i=0; i<N; i++){
    	if (i==0){
        	cin >> a;
        	min=a;
        	max=a;
        }
        else{
        	cin >> a;
            if (a<min) min=a;
            if (max<a) max=a;
        }
    }
    cout << max-min << endl;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      int x = Math.max(a,c);
      int y = Math.min(b,d);
      if(b < c||d < a) System.out.println(0);
      else System.out.println(y-x);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  bool t = true;
  int n = 0;
  int last;
  int size = (int)S.size();
  last = size-1;
  while(1) {
    if(n == last) break;
    if(S[n] != S[last]) {
      cout << "No";
      return 0;
    }
    ++n;
    --last;
  }
  n = 0;
  int lasta;
  lasta = (size-1) / 2-1;
  while(1) {
    if(n == lasta) break;
    if(S[n] != S[lasta] ) {
      cout << "No";
      return 0;
    }
    if(lasta-n==1) break;
    ++n;
    --lasta;
  }
  int start;
  start = (size + 3)/2-1;
  last = size-1;
  while(1) {
    if(start == last) break;
    if(S[start] != S[last]) {
      cout << "No";
      return 0;
    }
    if(last-start==1) break;
    ++start;
    --last;
  }
  if(t) cout << "Yes";
  if(t==false) cout << "No";
}
    


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int a[200000], b[200000];
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	b[n - 1] = a[n - 1];
	for (int i = n - 2; i >= 0; i--) 
		b[i] = max(b[i + 1], a[i]);
	int ans = -inf;
	for (int i = 0; i < n - 1; i++) {
		ans = max(ans, b[i + 1] - a[i]);
	}
	cout << ans << endl;
}


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

int main(){
  int a, b;
  cin >> a;
  for (int i = 1; i <= a; i++){
    if(i % 3 == 0){
      cout << " " << i;
    }else{
      b = i;
      while(b >= 3){
        if (b % 10 == 3){
          cout << " " << i;
          break;
        }
        b /= 10;
      }
    }
  }
  cout << endl;
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Min(a, b) ((a < b)? a : b)
#define Max(a, b) ((a > b)? a : b)
#define Abs(x) ((x>=0)? x : -x)/*Return the absolute value of x.*/
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, i, k=0;
	scanf("%d", &n);
	int p[n];
	rep(i,n) scanf("%d", &p[i]);
	loop(i, 1, n-1){
		if((p[i-1] < p[i]) &&(p[i] < p[i+1]) || (p[i+1] < p[i]) && (p[i] < p[i-1])){
			k++;
		}
	}
	printf("%d", k);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef pair<int,int> pii;
const int N = 10000;

void compute(int i,int *buf){
  buf[0]=i/1000%10;
  buf[1]=i/100%10;
  buf[2]=i/10%10;
  buf[3]=i%10;
}

pii hitAndBlow(int n,int q){
  int hit=0,blow=0;
  int buf1[5],buf2[5];
  compute(n,buf1);
  compute(q,buf2);
  rep(i,4){
    rep(j,4){
      if (buf1[i] == buf2[j]){
	if (i == j)hit++;
	else blow++;
      }
    }
  }
  return make_pair(hit,blow);
}

int solve(vector<int> &a,vector<int> all){
  if (a.size() > 15)return -1;
  rep(i,all.size()){
    int buf[5];
    bool isok=true;
    int cnt[5][5]={0};
    rep(j,a.size()){
      pii tmp = hitAndBlow(a[j],all[i]);
      cnt[tmp.first][tmp.second]++;
      if (cnt[tmp.first][tmp.second] > 1)isok=false;
    }
    if (isok)return all[i];
  }
  return -1;
}

main(){
  int n;
  vector<int> all(N);
  rep(i,N){
    int buf[4];
    compute(i,buf);
    bool isok=true;
    rep(j,4)REP(k,j+1,4)if (buf[j] == buf[k]){isok=false;}
    all[i]=(isok?i:-1);
  }
  sort(all.begin(),all.end());
  all.erase(remove(all.begin(),all.end(),-1),all.end());
  while(cin>>n && n){
    /*
    vector<pii> in(n);
    vector<int> cand,query(n);
    rep(i,n)cin>>query[i]>>in[i].first>>in[i].second;
    rep(i,all.size()){
      bool isok=true;
      int buf[5];
      rep(j,n){
	pii tmp =hitAndBlow(all[i],query[j]);
	if (tmp.first == in[j].first && tmp.second == in[j].second);
	else {
	  isok=false;
	}
      }
      if (isok)cand.push_back(all[i]);
    }
    sort(cand.begin(),cand.end());
    */
    vector<int> cand;
    cand=all;
    rep(k,n){
      vector<int> b;
      int q,hit,blow;
      cin>>q>>hit>>blow;
      rep(i,cand.size()){
	bool isok=true;
	pii tmp =hitAndBlow(q,cand[i]);
	if (hit == tmp.first && blow == tmp.second);
	else {
	  isok=false;
	}
	if (isok)b.push_back(cand[i]);
      }
      cand=b;
    }

    int ans = cand.size() == 1?cand[0]:solve(cand,all);
    if (ans !=-1)printf("%04d\n",ans);
    else puts("????");
  }
  return false;
}

Measured memory_bytes: 1000
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
int main() {
	map<char, int>u;
	u.insert(map<char, int>::value_type('m', 1000));
	u.insert(map<char, int>::value_type('c', 100));
	u.insert(map<char, int>::value_type('x', 10));
	u.insert(map<char, int>::value_type('i', 1));
	int v;
	cin >> v;
	for (int z = 0; z < v; z++) {
		string a, b;
		cin >> a >> b;
		int a2=0, b2=0;
		for (int i = 0; i < a.length(); i++) {
			if (a[i] >= '0'&&a[i] <= '9') {
				a2 += (u[a[i + 1]] * ((int)a[i] - '0'));
				i++;
			}
			else {
				a2 += u[a[i]];
			}
		}
		for (int i = 0; i < b.length(); i++) {
			if (b[i] >= '0'&&b[i] <= '9') {
				b2 += (u[b[i + 1]] * ((int)b[i] - '0'));
				i++;
			}
			else {
				b2 += u[b[i]];
			}
		}
		int c = a2 + b2;
		string d = "";
		int e = -1;
		char r[4] = { 'm','c','x','i' };
		int r2[4] = { 1000,100,10,1 };
		for (int i = 0; i < 4; i++) {
			e = 0;
			while (c >= r2[i]) {
				e++;
				c -= r2[i];
			}
			if (e != 0) {
				if (e >= 2) {
					d += to_string(e);
				}
				d += r[i];
			}
		}
		cout << d << endl;
	}
} 

Measured memory_bytes: 3092