akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, m; cin >> n >> m;
    map<int,int> mp;
    rep(i,m) {
        int a, b; cin >> a >> b;
        mp[a]++; mp[b]++;
    }
    for (P p : mp) {
        if (p.second&1) {cout << "NO" << endl; return 0;}
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 7668
n,y=map(int,input().split())

for i in range(0,n+1):
    for j in range(0,n-i+1):
        if 1000*(n-i-j)+5000*i+10000*j==y:
            print(j,i,n-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N;
  cin >> N;
  vi P(N), Q(N), A(N);
  REP(i, N) { cin >> P.at(i); }
  REP(j, N) { cin >> Q.at(j); }
  REP(k, N) { A.at(k) = k + 1; }
  int p = 0, q = 0, count = 0;
  do {
    count++;
    if (P == A) p = count;
    if (Q == A) q = count;
  } while (next_permutation(A.begin(), A.end()));

  cout << abs(p - q) << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

vector<int> next_combination(vector<int> now, int max)
{
	int i;
	int notmax = -1;
	int size = now.size();
	for (i = size - 1; i >= 0; i--) {
		if (now[i] != max) {
			notmax = i;
			break;
		}
	}
    if (notmax == -1)
		return now;
	now[notmax]++;
	for (i = notmax + 1; i < now.size(); i++) {
		now[i] = now[notmax];
	}
	
	return now;
}

int main(int argc, char *argv[])
{
    int n, m, q, i;
	vector<int> a, b, c, d;
	int tmpa, tmpb, tmpc, tmpd;
	int point = 0;
	int answer = 0;
	vector<int> perm;
	cin >> n >> m >> q;

	for (i = 0; i < q; i++) {
		cin >> tmpa >> tmpb >> tmpc >> tmpd;
		a.push_back(tmpa - 1);
		b.push_back(tmpb - 1);
		c.push_back(tmpc);
		d.push_back(tmpd);
	}
	for (i = 0; i < n; i++)
		perm.push_back(1);


	do {
		point = 0;
		for (i = 0; i < q; i++) {
			if (perm[b[i]] - perm[a[i]] == c[i])
				point += d[i];
		}
		   
		if (point > answer)
			answer = point;
	    if (perm == next_combination(perm, m))
			break;
		else
			perm = next_combination(perm, m);
	} while(1);
	
	cout << answer << endl;
	
	return 0;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

typedef enum{
	INT,
	PLUS,
	MINUS,
	MUL,
	DIV,
	EQ,
	LPAREN,
	RPAREN,
	NL
} token_kind_t;

typedef struct token{
	int c;
	token_kind_t kind;
	int ival;
} *token_t;

int calc_expr_add(token_t t);

token_t next_tok(token_t t)
{
	while (t->c == ' ' || t->c == '\n') {
		t->c = getchar();
	}
	if (isdigit(t->c)){
		t->ival = 0;
		t->kind = INT;
		while (isdigit(t->c)){
			t->ival *= 10;
			t->ival += t->c - '0';
			t->c = getchar();
		}
	}
	else{
		if (t->c == '+') t->kind = PLUS;
		else if (t->c == '-') t->kind = MINUS;
		else if (t->c == '*') t->kind = MUL;
		else if (t->c == '/') t->kind = DIV;
		else if (t->c == '(') t->kind = LPAREN;
		else if (t->c == ')') t->kind = RPAREN;
		else if (t->c == '=') t->kind = EQ;
		else if (t->c == '\n') t->kind = NL;
		else exit(1);

		t->c = getchar();
	}

	return t;
}

token_t mk_tok()
{
	token_t t;
	if ((t = (token_t)malloc(sizeof(struct token))) == NULL){
		perror("malloc");
		exit(1);
	}

	t->c = getchar();

	return t;
}

int calc_expr_un(token_t t)
{
	int ret = 0;
	if (t->kind == INT){
		ret = t->ival;
		next_tok(t);
	}
	else if (t->kind == LPAREN){
		next_tok(t);
		ret = calc_expr_add(t);
		if (t->kind != RPAREN) exit(1);
		next_tok(t);
	}
	else if (t->kind == PLUS || t->kind == MINUS){
		if (t->kind == PLUS){
			next_tok(t);
			ret += calc_expr_un(t);
		}
		else {
			next_tok(t);
			ret -= calc_expr_un(t);
		}
	}
	else exit(1);
	return ret;
}

int calc_expr_mul(token_t t)
{
	int ret = 0;
	ret = calc_expr_un(t);
	while (t->kind == MUL || t->kind == DIV){
		if (t->kind == MUL){
			next_tok(t);
			ret *= calc_expr_un(t);
		}
		else {
			next_tok(t);
			ret /= calc_expr_un(t);
		}
	}
	return ret;
}

int calc_expr_add(token_t t)
{
	int ret = 0;
	ret = calc_expr_mul(t);
	while (t->kind == PLUS || t->kind == MINUS){
		if (t->kind == PLUS){
			next_tok(t);
			ret += calc_expr_mul(t);
		}
		else {
			next_tok(t);
			ret -= calc_expr_mul(t);
		}
	}
	return ret;
}

int calc_expr(token_t t)
{
	int ret = 0;

	next_tok(t);
	ret = calc_expr_add(t);
	if (t->kind != EQ) exit(1);

	return ret;
}

int main()
{
	int i, n;

	n = 0;
	while (isdigit(i = getchar())){
		n *= 10;
		n += i - '0';
	}

	token_t t = mk_tok();

	for (i = 0; i < n; i++){
		int result = calc_expr(t);
		printf("%d\n", result);
	}

	return 0;
}

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

using namespace std;
/// 9:34

const int N = 15;
const long double eps = 1e-10;
typedef long long ll;

int n, i, j, x[N], y[N], A[N], cnt[1<<N];
ll a[1<<N];
long double apm[1<<N], dist[N+1], dp[1<<N], d[N][N];

long double solve()
{
    int mask, msk;
    for(mask = 1; mask < (1<<n); ++mask)
    {
        dp[mask] = 1.0 * (a[mask] - apm[mask]) / cnt[mask];
        for(msk = (mask-1) & mask; msk; msk = (msk-1) & mask)
            dp[mask] = max(dp[mask], min(dp[msk], dp[mask^msk]));
    }
    return dp[mask-1];
}

ll sq(int x) { return (ll)x*x; }

long double distant(int i, int j)
{
    return sqrt( sq(x[i] - x[j]) + sq(y[i] - y[j]) );
}

long double compute(int mask)
{
    int i, start;
    long double ans = 0;
    for(i=0; i<n; ++i)
        if(mask & (1<<i)) start = i;

    for(i=0; i<n; ++i) dist[i] = d[start][i];
    mask ^= (1<<start);

    while(mask)
    {
        start = n;
        for(i=0; i<n; ++i)
            if( (mask & (1<<i)) && dist[i] < dist[start] ) start = i;

        mask ^= (1<<start);
        ans += dist[start];

        for(i=0; i<n; ++i)
            if( (mask & (1<<i)) ) dist[i] = min(dist[i], d[start][i]);
    }
    return ans;
}

int main()
{
 //   freopen("input", "r", stdin);
 //   freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> n; dist[n] = 2e9;
    for(i=0; i<n; ++i)
        cin >> x[i] >> y[i] >> A[i];

    for(i=0; i<n; ++i)
        for(j=i; j<n; ++j)
            d[i][j] = d[j][i] = distant(i, j);

    for(i=1; i<(1<<n); ++i)
    {
        apm[i] = compute(i);
        cnt[i] = __builtin_popcount(i);
        for(j=0; j<n; ++j)
            if(i&(1<<j)) a[i] += A[j];
    }

    cout << setprecision(10) << fixed;
    cout << solve() << '\n';
    return 0;
}


Measured memory_bytes: 1664
long M=998244353,d[90310],e[90310],s,r=1,t;main(a){for(*d=*e=scanf("%d");~scanf("%d",&a);){for(t=s;~t;--t)d[t+a]+=d[t]*2%M,e[t+a]+=e[t]%M;s+=a;r=r*3%M;}for(t=s/2;~t;)r=(r-d[t--]*3)%M;printf("%d",(r-~s%2*e[s/2]*3+M)%M);}

Measured memory_bytes: 1536
n = int(input())
S = [list(input()) for i in range(n)]

M = [[] for i in range(n)]
for i in range(n):
    for j in range(n):
        if S[i][j] == "1":
            M[i].append(j)
ans = -1
owa = 0
for i in range(n):
    a0 = -1
    Q = [[i, 0]]
    st = 0
    D = [-1] * n
    while st < len(Q):
        a = Q[st][0]
        d = Q[st][1]
        D[a] = d
        for x in M[a]:
            if D[x] == -1:
                Q.append([x, d+1])
                D[x] = d+1
            elif D[x] != d-1 and D[x] != d+1:
                owa = 1
                break
        if owa == 1:
            break
        st += 1
    if owa == 0:
        a0 = max(D)+1
    ans = max(ans, a0)

print(ans)


Measured memory_bytes: 43756
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, pii> tri;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l, W, H;
int ans;

tri v[100001];
bool vis[100001];
vector<int> adj[100001];
ll dx[100001], dy[100001];
int vx[100001], vy[100001];
ll minx, miny;

int done[100001];

void failed() {
	cout << "No" << endl;
	exit(0);
}

void dfs(int i) {
	done[i] = 1;
	tri A = v[i];
	if (dx[A.first.first] < minx) minx = dx[A.first.first];
	if (dy[A.first.second] < miny) miny = dy[A.first.second];
	for (int j : adj[i]) {
		if (done[j]) continue;
		tri B = v[j];
		if (A.first.first == B.first.first) {
			if (!vy[B.first.second]) {
				vy[B.first.second] = 1;
				dy[B.first.second] = dy[A.first.second] + B.second.second - A.second.second;
			}
			else {
				if (dy[B.first.second] != dy[A.first.second] + B.second.second - A.second.second) failed();
			}
			dfs(j);
		}
		else {
			if (!vx[B.first.first]) {
				vx[B.first.first] = 1;
				dx[B.first.first] = dx[A.first.first] + B.second.second - A.second.second;
			}
			else {
				if (dx[B.first.first] != dx[A.first.first] + B.second.second - A.second.second) failed();
			}
			dfs(j);
		}
	}
}

void add_edges() {
	sort(v, v + n);
	F0(i, n - 1) if (v[i].first.first == v[i + 1].first.first) {
		adj[v[i].second.first].push_back(v[i + 1].second.first);
		adj[v[i + 1].second.first].push_back(v[i].second.first);
	}
}

int gx[1000000], gy[1000000];

int main() {
	//freopen("x.in", "r", stdin);
	
	cin >> W >> H >> n;
	F0(i, n) {
		cin >> v[i].first.first >> v[i].first.second >> v[i].second.second;
		v[i].second.first = i;
	}

	CL(0, vx);
	CL(0, vy);

	add_edges();
	F0(i, n) swap(v[i].first.first, v[i].first.second);
	add_edges();
	F0(i, n) swap(v[i].first.first, v[i].first.second);

	F0(i, n) swap(v[i].first, v[i].second);
	sort(v, v + n);
	F0(i, n) swap(v[i].first, v[i].second);
	F0(i, n) if (!done[i]) {
		vx[v[i].first.first] = 1;
		vy[v[i].first.second] = 1;
		dx[v[i].first.first] = 0;
		dy[v[i].first.second] = v[i].second.second;
		minx = 0;
		miny = v[i].second.second;
		dfs(i);
		if (minx + miny < 0) failed();
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 16256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

// unsigned euclidean_gcd(unsigned a, unsigned b) {
//   if (a < b)
//     return euclidean_gcd(b, a);
//   unsigned r;
//   while ((r = a % b)) {
//     a = b;
//     b = r;
//   }
//   return b;
// }

LL gcd(LL x, LL y) {
  return (x % y) ? gcd(y, x % y) : y;
}

void solve(long long K) {
  // solver code

  LL sum = 0;

  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        //
        LL tmp = gcd(a, b);
        LL res = gcd(tmp, c);
        // COUT(res);
        sum += res;
      }
    }
  }

  cout << sum << endl;
}

int main() {
  long long K;
  scanf("%lld", &K);
  solve(K);
  return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

bool comp(int a, int b) {
  if (a == 0) a = 10;
  if (b == 0) b = 10;
  return a < b;
}

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

  vector<int> a(5);
  rep(i, 5) cin >> a[i];

  int mi = 0;
  rep(i, 5) {
    if (comp(a[i]%10, mi))
      mi = a[i]%10;
  }

  int ans = 0;
  rep(i, 5) {
    if (a[i] % 10 == 0) {
      ans += a[i]/10*10;
    } else {
      ans += (a[i]/10+1)*10;
    }
  }
  cout << ans + mi - (mi == 0 ? 0 : 10) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  long long pts[n][n][2];
  for(int i=0;i<n;i++) 
    cin >> a[i];
  for(int l=0;l<n;l++) {
    for(int i=0;i<n;i++) {
      if (i+l>=n) {
        continue;
      }
      if (l==0) {
        pts[i][i+l][0] = a[i];
        pts[i][i+l][1] = 0;
      } else {
        // if I remove from right
        auto fromRight = a[i+l] + pts[i][i+l-1][1];
        auto fromLeft = a[i] + pts[i+1][i+l][1];
        if (fromRight - pts[i][i+l-1][0] > fromLeft - pts[i+1][i+l][0]) {
          pts[i][i+l][0] = fromRight;
          pts[i][i+l][1] = pts[i][i+l-1][0];
        } else {
          pts[i][i+l][0] = fromLeft;
          pts[i][i+l][1] = pts[i+1][i+l][0];
        }
      }
    }
  }
  cout << pts[0][n-1][0] - pts[0][n-1][1] << '\n';
  return 0;
}

Measured memory_bytes: 140288
n = gets(chomp:true).to_i

a = []
n.times{ a << gets(chomp:true).to_i }
@cnt = 0

def insertion_sort(a, n, g_itv)
  # 操作要素番号(i_ope_idx)
  (g_itv...n).each do |i_ope_idx|

    # 操作要素を一旦プール要素に格納(v_pol_elm)
    v_pol_elm = a[i_ope_idx]

    # 操作要素番号の左の比較要素番号(j_cmp_idx)
    j_cmp_idx = i_ope_idx - g_itv

    # 比較要素番号が配列の最初以上かつ、比較要素がプール要素（操作要素)より大きい場合
    while j_cmp_idx >= 0 && a[j_cmp_idx] > v_pol_elm

      # 比較要素を右へコピー（入れ替え）
      a[j_cmp_idx + g_itv] = a[j_cmp_idx]

      # 比較要素番号を間隔分左にずらす
      j_cmp_idx = j_cmp_idx - g_itv

      @cnt += 1
    end

    # 比較終了時番号の右にプール要素を戻す
    a[ j_cmp_idx + g_itv ] = v_pol_elm
  end
end

def shell_sort(a, n)

  @g = []
  h = 1

  until h > n
    @g.unshift(h)
    h = h*3 + 1
  end

  @g.each do |i|
    insertion_sort(a, n, i)
  end
end


shell_sort(a, n)

puts @g.size
puts @g.join(" ")
puts @cnt
n.times do |i|
  puts a[i]
end


Measured memory_bytes: 16140
#!/usr/bin/env python3

d = {}
while True:
    try:
        w, p = input().split()
    except:
        break

    try:
        d[w].add(int(p))
    except:
        d[w] = set()
        d[w].add(int(p))

l = list(d.keys())
l.sort()
for i in l:
    print(i)
    a = list(d[i])
    a.sort()
    print(" ".join(map(str, a)))

Measured memory_bytes: 6716
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if (S == "Sunny")
    {
        cout << "Cloudy";
    }
    if (S == "Cloudy")
    {
        cout << "Rainy";
    }
    if (S == "Rainy")
    {
        cout << "Sunny";
    }
    //
    return 0;
}

Measured memory_bytes: 3020
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

ll modpow(ll a,ll b){
	ll res = 1 ;
	while(b>0){
		if(b&1) res = res*a%mod ;
		b >>= 1 ;
		a = a*a%mod ;
	}
	return res ;
}


int main(){
	ld x,y ;
	cin >> x >> y ;
	ld a = (2*x-y)/3 ;
	ld b = (2*y-x)/3 ;
	if(a!=(int)a||a<0||b<0){
		cout << 0 << endl ;
		return 0 ;
	}
	vll fac(a+b+1,1) ;
	for(int i=2;i<=a+b;i++) fac.at(i) = fac.at(i-1)*i%mod ;
	cout << fac.at(a+b)*modpow(fac.at(a),mod-2)%mod*modpow(fac.at(b),mod-2)%mod << endl ;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define INF 1000000000

vector<ll> sum;
void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector
    ll n=(ll)a.size();
    s.assign(n+1,0);
    for(ll i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}
ll query(ll i,ll j,vector<ll> &s){//区間[i,j]の和
    return (s[j]-s[i]);
}

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

	pre_process(w,sum);

	int ans=INF;
	for(int i=1;i<=n-1;i++){
		ans=min(ans,abs(query(i,n,sum)-query(0,i,sum)));
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5555;
const long long inf = 1ll<<60;
long long dist[maxn];
int a[maxn], b[maxn], c[maxn], bad[maxn];
int main(){
	int n, m, p; cin >> n >> m >> p;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i] >> c[i];
		c[i] -= p;
	}
	for(int i = 1; i <= n; i++) dist[i] = -inf;
	dist[1] = 0;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j < m; j++){
			if(dist[a[j]] == -inf) continue;
			dist[b[j]] = max(dist[b[j]], dist[a[j]] + c[j]);
		}
	}
	for(int i = 0; i <= n; i++){
		for(int j = 0; j < m; j++){
			if(dist[a[j]] == -inf) continue;
			if(dist[b[j]] < dist[a[j]] + c[j]){
				dist[b[j]] = dist[a[j]] + c[j];
				bad[b[j]] = 1;
			}
			if(bad[a[j]]) bad[b[j]] = 1;
		}
	}
	if(bad[n]) cout << -1 << endl;
	else cout << max(dist[n], 0ll) << endl;
	return 0;
}


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

int main()
{
  long long L, R;

  cin >> L >> R;
  long long ret = 2018;

  if((R-L) > 2018){
    cout << 0 << endl;
    return 0;
  }

  for(long long i=L; i<R ;i++){
    for(long long j=(i+1); j<=R ; j++){
      ret = min(ret, (i*j)%2019);
    }
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int z,x,c,v,b;
    int maximum;
    cin>>z>>x;
    c=z+x;
    v=z-x;
    b=z*x;
    maximum=c;
    if(maximum<v){
        maximum=v;
    }
    if(maximum<b){
        maximum=b;
    }
    cout<<maximum<<"\n";
    return 0;
}

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

typedef long long ll;
const ll DIV = pow(10,9)+7;

int power(int a){
    ll multi = 1;
    for(int i=1;i<=a;i++){
        multi = (multi*i)%DIV;
    }
    return multi;
}

int main(){
    int N;
    cin >> N;
    ll ans = power(N);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

def solve():
    K = int(raw_input())
    print arr[K-1]

if __name__ == '__main__':
    solve()


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

int main()
{
	int m,d;
	cin >> m >> d;
	int ans = 0;
	for(int i = 4;i <= m;i++){
		for(int j = 2;j <= d;j++){
			if( j/10 >= 2 && j % 10 >= 2 && (j/10)*(j%10) == i)
				ans ++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
#define ll long long
#define bool int

using namespace std;

int main()
{
    string a,b,c,d;
    cin>>a>>b;
    if(a==b)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    int len = a.size(),count=0,i;
    int last=len-1,m;
    m=last-1;
    for(i=last;i>=0;i--)
    {
        if(i==last)
       c=a[last]+ a.substr(0,len);

       if(i!=last)
            c=c[last]+ c.substr(0,len);
        d=c.substr(0,len);

        if(d==b)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int hmax = 1e5+1;
int main(){
    int n; cin >> n;
    int h[hmax];
    rep(i, n) {
        cin >> h[i];
    }
    int maxcnt = 0;
    int cnt = 0;
    
    for(int i=1; i<n; i++){
        if(h[i] <= h[i-1]) {
            cnt++;
        } else {
            maxcnt = max(maxcnt, cnt);
            cnt = 0;
        }
    }
    maxcnt = max(maxcnt, cnt);
    cout << maxcnt << endl;
}

Measured memory_bytes: 640
N, M = map( int, input().split() )
H = list(map(int, input().split()) )
flg = [1] * N
for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] > H[B]:
        flg[B] = 0
    elif H[A] < H[B]:
        flg[A] = 0
    elif H[A] == H[B]:
        flg[A] = 0
        flg[B] = 0
print(sum(flg))

Measured memory_bytes: 20116
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (W, a, b) = (input[0], input[1], input[2])
print(max(max(b-(a+W), 0), max(a-(b+W), 0)))


Measured memory_bytes: 1920
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    26
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
#define INF         1000000005

typedef long long ll;
typedef unsigned long long ull;
// }}}

int main() {
    int group[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    cin >> x >> y;
    if(group[x] == group[y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

for i in range(0, n):
    a = int(input())
    b = int(input())
    if a + b >= 10 ** 80:
        print("overflow")
    elif a >= 10 ** 80:
        print("overflow")
    elif b >= 10 ** 80:
        print("overflow")
    else :
        print(a + b)

Measured memory_bytes: 7656
#include <bits/stdc++.h> 
 
using namespace std;
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

const int MAX_N=2e5+1;

int main(){
    LL N;cin>>N;
    vector<LL>a(N),b(N+1);
    REP(i,N){
        cin>>a[i];
        b[a[i]]=i;
    }
    set<LL>st;
    LL res=0;
    REP(i,N){
        st.insert(b[i+1]);
        auto itr=st.find(b[i+1]);
        LL l=-1,r=-1;
        auto itr2=itr;
        if(itr!=st.begin()){
            itr2--;l=*itr2;
        }else{
            l=-1;
        }
        itr2=itr;
        itr2++;
        if(itr2!=st.end()){
            r=*itr2;
        }else{
            r=N;
        }
        //cout<<i+1<<":"<<l<<" "<<*itr<<" "<<r<<endl;
        LL tmp=(*itr-l)*(r-*itr)*(i+1LL);
        //cout<<tmp<<endl;
        res+=tmp;
    }
    cout<<res<<endl;
    return 0;
}
//各要素が最小値になりうるのは何回か？
//i番目より前でa[i]より小さい数はどこにあるか？
//i番目より後でa[i]より小さい数はどこにあるか？



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

typedef long long int ll;

int main () {

	ll n;
	cin >> n;


	if (n%2!=0) {
		cout << 0 << endl;
		return 0;
	}

	ll fac = 5;
	ll ans = 0;

	while ((n/fac)>0) {
		ans += (n/(2*fac));
		fac *= 5;
	}


	cout << (ans) << endl;
}

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

int main() {
  int A,B;
  string S;

  cin >> A >> B >> S;
  for(int i=0;i<S.size();++i){
    if(i == A){
      if(S.at(i) == '-'){
        continue;
      }else{
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(S.at(i) == '-'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3568
n = gets.chomp.to_i

board = []
10.times do |i|
  board << Array.new(10,0)
end

n.times do |i|
  str = (i+1).to_s
  board[str[0].to_i][str[-1].to_i] += 1
end

count = 0

10.times do |i|
  10.times do |j|
    count += board[i][j]*board[j][i]
  end
end

puts count

Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long A[200000];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  map <long long, int> map_A;
  for(int i = 0; i < N; i++){
    if(A[i] < N){
      if(map_A.find(i - A[i]) == map_A.end()){
        map_A[i - A[i]] = 1;
      } else {
        map_A[i - A[i]] ++;
      }
    }
  }

  long long ans = 0;
  for(int i = 0; i < N; i++){
    auto it = map_A.find(i - A[i]);
    if(it->second == 1){
      map_A.erase(i - A[i]);
    } else {
      it->second --;
    }
    auto it_tmp = map_A.find(i + A[i]);
    if(it_tmp != map_A.end()){
      ans += (int) it_tmp->second;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14296
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string s,ss[55555];
int k,cnt;
int main()
{
	cin>>s>>k;
	for (int i=1;i<=s.size() && i<=5;i++)
	{
		for (int j=0;j<=s.size()-i;j++)
		{
			ss[++cnt]=s.substr(j,i);
		}
	}
	sort(ss,ss+cnt+1);
	unique(ss,ss+cnt+1);
	cout<<ss[k]<<endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	rep(i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		rep(j, k) {
			int v;
			cin >> v;
			v--;
			g[u].push_back(v);
		}
	}
	vector<int> d(n, -1);
	d[0] = 0;
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (auto nv : g[v]) {
			if (d[nv] != -1) continue;
			d[nv] = d[v] + 1;
			q.push(nv);
		}
	}
	rep(i, n) cout << i + 1 << " " << d[i] << endl;
	return 0;
}


Measured memory_bytes: 3156
#include<stdio.h>


int main() {
	int n ;
	scanf("%d", &n);
	int ans = 0 ;
	int f[n], s[n];
	for (int i = 0 ; i < n ; i++) {
		scanf("%d", &f[i]);
		scanf("%d", &s[i]);
	}

	for (int i = 0; i < n - 2 ; i++) {
		if (f[i] == s[i] && f[i + 1] == s[i + 1] && f[i + 2] == s[i + 2]) {
			ans = 1  ;
			break;
		}
	}
	ans ? printf("Yes") : printf("No");
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B&&A!=C) cout << "Yes" << endl;
  else if(A==C&&A!=B) cout << "Yes" << endl;
  else if(B==C&&A!=B) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string S;
    int count1 = 0,count0=0;
    cin >> S;
    for(int i=S.size()-1;i>=0;i--){
        if(S[i]=='1'){
        count1++;
        }else{
        count0++;
        }
    }
    cout << 2*min(count0,count1) <<endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int N,c=0,p=0,r,temp;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        temp = i;
        while(temp!=0)
        {
           r = temp%10;
           temp = temp/10;
           c++;
        }
        if(c%2!=0)
        {
           p++;
        }
        c=0;
    }
    printf("%d\n",p);
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;
int h,w;
int c[10][10];
int ch[10];
int cost[10];
map <int,int> a={};

int main(){
	cin>>h>>w;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<w;i++){
		for(int i=0;i<h;i++){
			int t;
			cin>>t;
			a[t]++;
		}
	}
	for(int i=0;i<10;i++){
		cost[i]=c[i][1];
	}
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(i!=1&&j!=1&&i!=j){
					cost[i]=min(cost[j]+c[i][j],cost[i]);
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<10;i++){
		ans+=a[i]*cost[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, P;
  cin >> N >> P;

  i64 k1 = 0, k0 = 0;
  rep(i,N){
    i64 a;
    cin >> a;
    if(a&1) k1++;
    else k0++;
  }

  i64 ans;
  if(k1 == 0) {
    ans = 1LL << N;
  } else {
    ans = 1LL << (N - 1);
  }

  if(P == 1) {
    ans = (1LL << N) - ans;
  }

  cout << ans;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
 
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    pair<int,pair<pair<int,int>,int>> p[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>p[i].ss.ff.ff>>p[i].ss.ff.ss>>p[i].ss.ss;
        p[i].ff=(p[i].ss.ff.ff + p[i].ss.ff.ss);
    }
    sort(p,p+n,greater<pair<int,pair<pair<int,int>,int>>>());
    int dp[2][20005];
    memset(dp,0,sizeof(dp));
    int ans=0;
    int c=1;
    for(int i=0;i<n;i++)
    {
        //cout<<p[i].ff<<" "<<p[i].ss.ff.ff<<" "<<p[i].ss.ff.ss<<" "<<p[i].ss.ss<<"\n";
        for(int j=0;j<=10000;j++)
            dp[c][j]=dp[!c][j];
        for(int j=p[i].ss.ff.ff;j<=20000;j++)
        {    
            dp[c][min(j - p[i].ss.ff.ff,p[i].ss.ff.ss)]=max(dp[!c][j] + p[i].ss.ss,dp[c][min(j - p[i].ss.ff.ff,p[i].ss.ff.ss)]) ;
            ans=max(ans ,dp[c][min(j - p[i].ss.ff.ff,p[i].ss.ff.ss)] );
        }
        //cout<<ans<<" \n";
        c^=1;
    }
    cout<<ans;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 20;
int n;
int c[MAX_N];
int v[MAX_N];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) cin >> v[i];
  forn(i,n) cin >> c[i];

  int res = 0;
  for (int i = 0; i < (1 << n); i++) {
    int temp = 0;
    for (int j = 0; j < n; j++) {
      if (i & (1<<j)) {
        temp += v[j] - c[j];
      }
    }
    chmax(res,temp);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

int n;

main()
{
    cin>>n;

    if(n==3||n==5||n==7)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
float x[100],y[100],t,u,a,b;n,i,j,k,c,s;main(m){for(;m=scanf("%d",&n),c=i=n;printf("%d\n",m))for(;c?scanf("%f,%f",x+c,y+--c):--i;)for(j=i;s=!c&&j--;)for(u=acos(hypot(a=x[j]-x[i],b=y[j]-y[i])/2),t=atan2(b,a);c=0,u<9&&s+3;s-=2)for(a=x[i]+cos(b=t+s*u),b=y[i]+sin(b),k=n;k--;)hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define X first
#define Y second
#define pb push_back
#define sz(a) (int)a.size()

void solve();

signed main() {
#ifdef ONPC
    freopen("in.txt", "r", stdin);
#endif // ONPC
    //freopen("time.in", "r", stdin);
    //freopen("time.out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
    return 0;
}

const int N = 2e5 + 5;
const int lg = 20;
ll n, a[N], lef[N][lg + 1];
ll ans;

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < lg; ++j) {
            lef[i][j] = lef[i - 1][j];
            if (i != 1 && ((1 << j) & a[i - 1])) lef[i][j] = i - 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        ll l = 0;
        for (int j = 0; j < lg; ++j) {
            if ((1 << j) & a[i]) {
                l = max(l, lef[i][j] + 1);
            } else {
                l = max(l, lef[lef[i][j]][j] + 1);
            }
        }
        ans += i - l + 1;
    }
    cout << ans;
}


Measured memory_bytes: 34688
def erato(n):
    s = list(range(n+1))
    s[1] = 0
    for e in s:
        if e:
            for i in range(e*2, n+1, e):
                s[i] = 0
    return s
e = erato(1000000)
while True:
    try:
        n = int(input())
        print(len(list(filter(lambda x:x, e[:n+1]))))
    except:
        break

Measured memory_bytes: 55944
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e18 + 7LL;
constexpr ll MOD = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    int n;
    cin >> n;
    vint d(n);
    cin >> d;
    ll ans = 0;
    REP(i, n)
    {
        REP(j,n){
            if (i < j){
                ans += d[i] * d[j];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main() {
  
  string s; 
  cin>>s ;
  set<char> a ;
  a.insert(s[0]) ;

  for (int i = 1; i < s.size(); i++)
  {
    if(a.find(s[i])!=a.end()){
        cout << "no" << endl ;
        return 0 ;
    }

    a.insert(s[i]) ;

  }
  
  cout << "yes" << endl ;

return 0 ;

}

Measured memory_bytes: 256
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
 
fn main() {
    input!(
        s: String,
        t: String,
        a: usize,
        b: usize,
        u: String,
    );
    let ss = if s==u { a-1 } else { a };
    let tt = if t==u { b-1 } else { b };
    println!("{} {}", ss, tt);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    ll dp[n];
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<=n;i++)
    {
        dp[i]=min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]);
    }
    cout<<dp[n-1];
    return 0;
}









Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define F  first
#define S  second

/*
bool compare (pair<ll,ll> x,pair<ll,ll> y)
    {   
        if(x.F==y.F)return x.S<y.S;
        return x.F<y.F;
    }
*/
int main()
{
    /*  if you are getting wrong on test case 2 then think of another proper logic 
        if you are getting wrong on test case 4 then think of edge cases 
        like n=0,n=n-1&& k=0&& k=k-1;
    */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t>0)
    {
        t--;
        ll n,k,a,b,c,x,y,z;
        ll max=LONG_MIN;
        ll min=LONG_MAX;
        ll flag=0,sum=0;
        ll cnt=0,ans=0,gcd=1;
        cin>>x>>y;
        if((4*x-y)%2==0&&(y-2*x)%2==0&&((4*x-y)>=0)&&((y-2*x)>=0))
            cout<<"Yes\n";
        else cout<<"No\n";
    }
}


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

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


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

int main()
{
    int n;
    cin >> n;
    map<int, int> n_cnt;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        n_cnt[a]++;
    }
    int ans = 0;
    for (auto n_c: n_cnt)
        ans += int(n_c.second % 2 == 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4864
#include<cstdio>
#include<algorithm>
using namespace std;
long long n;
int main(){
    scanf("%lld",&n);
    long long i, j, k;
    for(i=1;i<=3500;i++){
        for(j=1;j<=3500;j++){
            long long t = 4*i*j - j*n - i*n;
            long long tt = i*j*n;
            if(t>0 && tt%t == 0){
                printf("%d %d %lld\n",i,j,tt/t);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void){
	int i, j, n, max;
	scanf("%d", &n);
	int a[200000];
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int flag =1;
	int cnt = 0, tmp;

	while(flag){
		flag =0;
		for(j=n-1;j>=1;j--){
			if(a[j]<a[j-1]){
				tmp = a[j];
				a[j] = a[j-1];
				a[j-1] = tmp;
				cnt++;
				flag = 1;
			}
		}
	}
	for(i = 0;i<n-1;i++){
		printf("%d ", a[i]);
	}
	printf("%d\n", a[n-1]);
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 1968
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))+[0]
ans=0
for i in range(n+1):
  if a[i]>=b[i]:
    ans+=b[i]
  else:
    ans+=a[i]
    d=b[i]-a[i]
    if a[i+1]>d:
      ans+=d
      a[i+1]-=d
    else:
      ans+=a[i+1]
      a[i+1]=0
print(ans)

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

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

    int x;
    int num = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> x;
        if (K >= x)
        {
            if (2 * x >= 2 * (K - x))
            {
                num += 2 * (K - x);
            }
            else
            {
                num += 2 * x;
            }
        }
        else
        {
            if (2 * x >= 2 * (x - K))
            {
                num += 2 * (x - K);
            }
            else
            {
                num += 2 * x;
            }
        }
    }

    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
	ld n;
	cin >> n;
	cout << setprecision(10) << static_cast<ld>((n/3.0)*(n/3.0)*(n/3.0)) << endl;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] hako = new int[1001];
            int a = 0;
            hako[0] = 0;
            string[] str = Console.ReadLine().Split(' ');
            for (int i = 1; i < 1000; i++)
            {
                a += i;
                hako[i] = a;
            }
            int b, c;
            b = int.Parse(str[0]);
            c = int.Parse(str[1]);
            Console.Write(hako[c - b] - c);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    ll a[5];
    ll min = -1;
    int poji = -1;
    for(int i = 0; i < 5; i++){
        cin >> a[i];
        if(min == -1){
            min = a[i];
            poji = i;
        }else if(min > a[i]){
            min = a[i];
            poji = i;
        }
    }

    ll ans = 0;

    if(n > min){
        if(n % min == 0){
            ans += n / min;
        }else{
            ans += n / min + 1;
        }
        ans += 4;
    }else{
        ans = 5;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256