akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
pii a[maxn];
int b[maxn];
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].F>>a[i].S;
        b[i]=i;
    }
    long double cntr=0;
    long double kol=0;
    do{
        kol++;
        for(int j=2;j<=n;j++){
            int i=b[j];
            int i1=b[j-1];
            long double x=(a[i].F-a[i1].F)*(a[i].F-a[i1].F);
            long double y=(a[i].S-a[i1].S)*(a[i].S-a[i1].S);
            cntr+=sqrt(x+y);
        }
    }while(next_permutation(b+1,b+1+n));
    cout<<fixed<<setprecision(6)<<cntr/kol;
	exit(0);
}


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

typedef long long ll;

int main(){
	const int MOD = 1e9+7;
	string L;
	cin >> L;
	int n = L.size();
	vector<vector<int>> dp(100005, vector<int>(2));
	dp[0][0] = 1;

	rep(i,n){
		// a+b = 0
		if(L[i] == '0'){
			dp[i+1][0] = dp[i][0];
			dp[i+1][1] = dp[i][1];
		}else{
			dp[i+1][1] = (dp[i][0] + dp[i][1] ) % MOD;
		}

		// a+b = 1
		if(L[i] == '0'){
			dp[i+1][1] += (dp[i][1]*2%MOD);
			dp[i+1][1] %= MOD;
		}else{
			dp[i+1][0] += dp[i][0]*2%MOD;
			dp[i+1][1] += dp[i][1]*2%MOD;
			dp[i+1][0] %= MOD;
			dp[i+1][1] %= MOD;
		}
	}

	int ans = (dp[n][0] + dp[n][1]) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


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

  long n,m;
  cin >> n >> m;

  vector<long> a(n);
  fillLong(a, n);

  priority_queue<long> que;
  rep(i, n) {
    que.push(a[i]);
  }

  rep(i, m) {
    long x = que.top();
    que.pop();
    que.push(x/2);
  }

  long res = 0;
  rep(i, n) {
    res += que.top();
    que.pop();
  }

  cout << res << endl;
 
  
}


Measured memory_bytes: 2168
def dfs(i,sent):
    if len(sent)==N:
        print(sent)
        return
    if i>N:
        return
    for j in range(i+1):
        dfs(max(i,j+1),sent+chara[j])
    return

N=int(input())
chara=["a","b","c","d","e","f","g","h","i","j"]
chara=chara[:N]
ans=[]
dfs(1,"a")

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  int a, b, c, d ;
  cin >> a >> b >> c >> d;
  int ab = a+b;
  int cd = c+d;
  if (ab > cd) {
    cout << "Left" << endl;
  } else if (ab < cd) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc172/tasks/abc172_f

#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 300;
const ull A_I_MAX = 1e12;

int N;
vector<ull> A;

vector<vector<ull>> v;

int main() {
  cin >> N;
  A = vector<ull>(N);
  REP(i, N) cin >> A[i];

  ull X = 0;
  FOR(i, 2, N - 1) X ^= A[i];
  // cout << "X:" << X << endl;

  v = vector<vector<ull>>(41);

  ull Y = A[0] ^ A[1] ^ X;
  // cout << "d:" << 0 << " Y:" << Y << endl;
  if (Y == 0) {
    cout << 0 << endl;
    return 0;
  }
  v[0].push_back(0);
  FOR(j, 0, 39) {
    if (Y >> j & 1) break;
    v[j + 1].push_back(0);
  }


  FOR(i, 0, 39) {
    // cout << "v[" << i << "]: ";
    // DUMP(v[i]);
    ull q = 1ULL << i;
    for (ull r : v[i]) {
      ull d = q + r;
      if (d >= A[0]) {
        cout << -1 << endl;
        return 0;
      }
      ull Y = (A[0] - d) ^ (A[1] + d) ^ X;
      // cout << "d:" << d << " Y:" << Y << endl;
      if (Y == 0) {
        cout << d << endl;
        return 0;
      }
      FOR(j, i, 39) {
        if (Y >> j & 1) break;
        v[j + 1].push_back(d);
      }
    }
  }

  cout << -1 << endl;
}


Measured memory_bytes: 699960
from bisect import bisect_left

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

# longest increasing subsequence
def lis(li):
    lis_li = [li[0]]
    for i in li:
        if i > lis_li[-1]:
            lis_li.append(i)
        else:
            lis_li[bisect_left(lis_li, i)] = i
    return lis_li

rA = lis(A)

if rA[0] != 1:
    print(-1)
else:
    count = 0
    for i in range(len(rA)):
        if rA[i] == i + 1:
            count += 1
    print(N - count)

Measured memory_bytes: 85584
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    int n   = s.size();
    int ret = 0;
    for (int i = 0; i < n / 2; ++i) {
        if (s[i] != s[n - 1 - i])
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

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

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

  string answer="AC";
  
  if (s.at(0)!='A'){
    answer="WA";
  }
  
  int count=0;
  
  
  for (int i=2;i<=n-2;i++){
    if (answer=="WA"){
      break;
    }
    
    if (count>=2){
      answer="WA";
      break;
    }
    
    if (s.at(i)=='C'){
      count+=1;
    }
  }
  
  if (count==0 or count>=2){
    answer="WA";
  }
  
  else if (s.at(1)<'a' or 'z'<s.at(1)){
    answer="WA";
  }
  
  else if (s.at(n-1)<'a' or 'z'<s.at(n-1)){
    answer="WA";
  }
  
  for (int i=2;i<=n-2;i++){
    if (answer=="WA"){
      break;
    }
    
   
    if ((s.at(i)<'a' or 'z'<s.at(i)) and (s.at(i)!='C')){
      answer="WA";
      break;
    }
  }
  
  
 cout<<answer<<endl;
  

    
    
}
  













Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

int gcd(int a, int b){ return (a % b) ? gcd(b, a % b) : b;}
int lcm(int a, int b){ return (a / gcd(a, b)) * b;}

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

const int inf = 1012345678;
int main(){
    int n, m;
    int k[35];
    int a[35][35];
    int memo[35][35] = {0};
    int ans[35];

    for(int i = 0; i < 35; ++i){
        ans[i] = 1;
    }
    //printf("%d\n", ans[4]);

    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; ++i){
        scanf("%d", &k[i]);
        for(int j = 0; j < k[i]; ++j){
            scanf("%d", &a[i][j]);
            memo[i][a[i][j]] = 1;
        }
    }

    for(int i = 0; i < n; ++i){
        for(int j = 1; j <= m; ++j){
            //printf("%d\n", ans[j]);
            ans[j] = (memo[i][j] & ans[j]);
        }
    }

    int cnt = 0;
    for(int i = 1; i <= m; ++i){
        //printf("%d\n", ans[i]);
        if(ans[i] == 1) cnt++;
    }

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

    return 0;
}


Measured memory_bytes: 1724
#include <stdio.h>

int main(){
  int n, number;
  char suit[2];
  int cards[4][13];

  for(int i = 0; i < 4; i++){
	for(int j = 0; j < 13; j++){
	  cards[i][j] = 0;
	}
  }

  scanf("%d", &n);

  for(int i = 0; i < n; i++){
	scanf("%1s %d", suit, &number);
	if(suit[0] == 'S'){cards[0][number - 1] = 1;}
	if(suit[0] == 'H'){cards[1][number - 1] = 1;}
	if(suit[0] == 'C'){cards[2][number - 1] = 1;}
	if(suit[0] == 'D'){cards[3][number - 1] = 1;}
  }

  for(int i = 0; i < 4; i ++){
	for(int j = 0; j < 13; j++){
	  if(cards[i][j] == 0){
		switch(i){
		case 0:
		  printf("S %d\n", j + 1);
		  break;
		case 1:
		  printf("H %d\n", j + 1);
		  break;
		case 2:
		  printf("C %d\n", j + 1);
		  break;
		case 3:
  		  printf("D %d\n", j + 1);
		  break;
		default:
		  break;
		}
	  }
	}
  }

  return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//141 Who Says a Pun?
vector<int> Zalgorithm(const char *s) {
	int len = strlen(s);
	vector<int> prefix(len);
	for (int i = 1, j = 0; i < len; i++) {
		if (i + prefix[i - j] < j + prefix[j]) {
			prefix[i] = prefix[i - j];
		}
		else {
			int k = max(0, j + prefix[j] - i);
			while (i + k < len && s[k] == s[i + k]) ++k;
			prefix[i] = k;
			j = i;
		}
	}
	prefix[0] = len;
	return prefix;
}

int main() {
	int N;
	scanf("%d", &N);
	char s[101010];
	scanf("%s", s);

	int result = 0;

	for (int i = 0; i < N - 1; i++) {
		auto prefix = Zalgorithm(s + i);

		int len = N - i;
		for (int j = 1; j < prefix.size(); j++) {
			result = max(result, min(prefix[j], j));
		}
	}

	printf("%d\n", result);
}


//139 League
/*
struct LLPair {
	int a = 0;
	int b = 0;
	LLPair() {}
	LLPair(int a, int b) {
		this->a = a;
		this->b = b;
	}
};

int main() {
	int N;
	scanf("%d", &N);
	vector<vector<int>> A(N, vector<int>(N - 1, 0));
	for (int j = 0; j < N; j++) {
		for (int i = 0; i < N - 1; i++) {
			scanf("%d", &A[j][i]);
			A[j][i]--;
		}
	}

	vector<vector<vector<LLPair>>> graph(N, vector<vector<LLPair>>(N, vector<LLPair>(0)));
	vector<vector<vector<LLPair>>> graphR(N, vector<vector<LLPair>>(N, vector<LLPair>(0)));
	vector<vector<int>> inEdge(N, vector<int>(N, 0));
	for (int j = 0; j < N; j++) {
		for (int i = 0; i < N - 2; i++) {
			int a = j;
			int b = A[j][i];
			if (a > b) {
				swap(a, b);
			}

			int c = j;
			int d = A[j][i + 1];
			if (c > d) {
				swap(c, d);
			}

			graph[a][b].push_back(LLPair(c, d)); //a vs b �̌�� c vs d ���s��			
			graphR[c][d].push_back(LLPair(a, b)); //c vs d ���s���O�� a vs b
			inEdge[c][d]++; //c vs d �ւ̗����G�b�W��
		}
	}

	//���[�v�̌��o���g�|���W�J���\�[�g�Ŏ��{

	queue<LLPair> S; //���������N����0�ł���m�[�h�̃Z�b�g
	vector<LLPair> L; //�g�|���W�J���\�[�g�̌���
	
	for (int j = 0; j < N; j++) {
		for (int i = j + 1; i < N; i++) {
			if (graphR[j][i].size() == 0) {
				S.push(LLPair(j, i));
			}
		}
	}

	while (S.empty() == false) {
		LLPair node = S.front();
		S.pop();
		L.push_back(node);

		for (auto next : graph[node.a][node.b]) {
			inEdge[next.a][next.b]--;
			if (inEdge[next.a][next.b] == 0) {
				S.push(LLPair(next.a, next.b));
			}
		}
	}

	//���[�v�����݂���ꍇ�͉��Ȃ�
	if ((int)L.size() < N * (N - 1) / 2) {
		printf("-1\n");
		return 0;
	}

	int result = 0;
	stack<LLPair> st;
	vector<vector<int>> dist(N, vector<int>(N, 1));

	int maxDist = 0;

	for (auto node : L) {
		int d = dist[node.a][node.b];

		for (auto next : graph[node.a][node.b]) {
			if (d + 1 > dist[next.a][next.b]) {
				dist[next.a][next.b] = d + 1;
				maxDist = max(maxDist, d + 1);
			}
		}
	}

	result = maxDist;

	printf("%d\n", result);
}
*/


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

using namespace std;

void sort(int card[5])
{
	for(int i=0;i<5;i++)
	{
		int max=i;
		for(int j=i+1;j<5;j++)
		{
			if(card[max]<card[j])
			{
				max=j;
			}
		}
		int tmp=card[i];
		card[i]=card[max];
		card[max]=tmp;
	}
}

bool fourcard(int card[5])
{
	if((card[0]==card[1]&&card[1]==card[2]&&card[2]==card[3])||
		(card[1]==card[2]&&card[2]==card[3]&&card[3]==card[4]))
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool fullhouse(int card[5])
{
	if((card[0]==card[1]&&card[2]==card[3]&&card[3]==card[4])||
		(card[0]==card[1]&&card[1]==card[2]&&card[3]==card[4]))
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool straight(int card[5])
{
	if((card[0]-1==card[1]&&card[1]-1==card[2]&&card[2]-1==card[3]&&card[3]-1==card[4])||
		(card[0]==13&&card[1]==12&&card[2]==11&&card[3]==10&&card[4]==1))
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool threecard(int card[5])
{
	if((card[0]==card[1]&&card[1]==card[2])||
		(card[1]==card[2]&&card[2]==card[3])||
		(card[2]==card[3]&&card[3]==card[4]))
	{
		return true;
	}
	else{
		return false;
	}
}

bool twopair(int card[5])
{
	if((card[0]==card[1]&&card[2]==card[3])||
		(card[0]==card[1]&&card[3]==card[4])||
		(card[1]==card[2]&&card[3]==card[4]))
	{
		return true;
	}
	else return false;
}

bool onepair(int card[5])
{
	if(card[0]==card[1]||
		card[1]==card[2]||
		card[2]==card[3]||
		card[3]==card[4])
	{
		return true;
	}
	else return false;
}

char *solve(int card[5])
{
	sort(card);
	if(fourcard(card))
	{
		return "four card";
	}
	else if(fullhouse(card))
	{
		return "full house";
	}
	else if(straight(card))
	{
		return "straight";
	}
	else if(threecard(card))
	{
		return "three card";
	}
	else if(twopair(card))
	{
		return "two pair";
	}
	else if(onepair(card))
	{
		return "one pair";
	}
	else
	{
		return "null";
	}
}

int main(void)
{
	int card[5];
	char c;
	while(cin>>card[0])
	{
		for(int i=1;i<5;i++)
		{
			cin>>c>>card[i];
		}
		cout<<solve(card)<<endl;
	}
}

Measured memory_bytes: 1160
package main

import "fmt"

const limit = 100001

func main() {
	nums := make([]bool, limit)
	for i := 2; i < limit; i++ {
		nums[i] = true
	}
	for i := 2; i < limit; i++ {
		if nums[i] {
			for j := 2; i*j < limit; j++ {
				nums[i*j] = false
			}
		}
	}

	like2017 := make([]int, limit)
	for i := 0; i < limit; i++ {
		if i%2 == 0 {
			continue
		}
		if nums[i] && nums[(i+1)/2] {
			like2017[i] = 1
		}
	}

	s := make([]int, limit+1)
	for i := 0; i < limit; i++ {
		s[i+1] = s[i] + like2017[i]
	}

	var q, l, r int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&l, &r)
		fmt.Println(s[r+1] - s[l])
	}
}


Measured memory_bytes: 5888
def element_count(element, start, sum, target)
  result = []
  start.upto(9) do |i|
    if element == 1
      tmp = (i + sum) == target ? true : false
      result << tmp
    else
      result += element_count(element - 1, i + 1, sum + i, target)
    end
  end
  result
end

while str = gets
  n, s = str.split(' ').map(&:to_i)
  break if n == 0 && s == 0
  result = element_count(n, 0, 0, s)
  puts result.select { |el| el }.count
end

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    ll ans = 0;
    for (int i = 0; i < 60; ++i) {
        int cnt1 = 0;
        for (int j = 0; j < n; ++j) {
            if (a[j] & (1LL << i)) {
                (ans += (1LL << i) % MOD * (j - cnt1) % MOD) %= MOD;
                cnt1++;
            } else {
                (ans += (1LL << i) % MOD * cnt1 % MOD) %= MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
s = list(input())
s.append("1")
s.append("2")
N = len(s)
for i in range(N-2):
    now = s[i]
    if s[i+1] == now:
        print(i+1,i+2)
        break
    if s[i+2] == now:
        print(i+1,i+3)
        break
else:
    print(-1,-1)

Measured memory_bytes: 50288
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;
const int N = 3003;

int n, a[N];
LL f[N][N];

void input() {
	cin >> n;
	fort(i, 1, n) cin >> a[i];
}

void solve() {
	fort(i, 1, n) f[i][i] = a[i];
	fort(l, 2, n) fort(i, 1, n - l + 1) {
		int j = i + l - 1;
		f[i][j] = max(a[i] - f[i + 1][j], a[j] - f[i][j - 1]);
	}	
	cout << f[1][n] << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	input();
	solve();
    return 0;
}


Measured memory_bytes: 70144
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
ll dp[4005][4005][3];
void solve()
{
  ll n;
  cin>>n;
  string s;
  cin>>s;
  rep(i,0,n) {if(s[i]=='R') s[i]='a';
  if(s[i]=='G') s[i]='b';
  if(s[i]=='B') s[i]='c';
}
// cout<<s<<endl;
  rep(i,1,n)
  {
    rep(j,0,i)
    {
      if(s[i]!=s[j])
      {
        dp[i][i-j][s[j]-'a']--;
        dp[i][4001][s[j]-'a']++;
      }
    }
  }
  ll ans=0;
  rep(i,2,n)
  {
    rep(j,1,i)
    {
      if(s[i]==s[j]) continue;
      rep(k,0,3) 
      {
        if(((s[i]-'a')!=k)&&((s[j]-'a')!=k))
        {
          ans+=dp[j][4001][k]+dp[j][i-j][k];
        }
      }
    }
  }
  cout<<ans;
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 207144
fun main(arg: Array<String>) {
    val N = next()
    val K = nextInt()
    val L = N.length
    val dp = Array(101) { Array(4) { IntArray(2) } }
    dp[0][0][0] = 1
    for (i in 0 until L)
        for (j in 0 until 4)
            for (k in 0 until 2) {
                val nd = N[i] - '0'
                for (d in 0 until 10) {
                    var ni = i + 1
                    var nj = j
                    var nk = k
                    if (d != 0) nj += 1
                    if (nj > K) continue
                    if (k == 0) {
                        if (d > nd) continue
                        if (d < nd) nk = 1
                    }
                    dp[ni][nj][nk] += dp[i][j][k]
                }
            }
    var ans = dp[L][K][0] + dp[L][K][1]
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())


Measured memory_bytes: 33780
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int ll

int n, m, g;
int32_t main()
{
    cin >> n >> m;
    g = __gcd(n,m);
    int ct = 1;
    for (int i = 2; i<=1000000; i++)
    {
        if (g%i==0)
        {
            while(g%i==0)
                g/=i;
            ct++;
        }
    }
    if (g > 1)
        ct++;
    cout << ct << '\n';    
}

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

int kaijo(int x){
  if(x==0)
    return 1;
  else{
  	int y=1;
  	for(int i=0;i<x;i++)
      y*=i+1;
  	  return y;
  }
}

int main(){
  int N;
  cin>>N;
  vector<int> P(N),Q(N),R(N),X(N);
  for(int i=0;i<N;i++)
    cin>>P.at(i);
  for(int i=0;i<N;i++)
    cin>>Q.at(i);
  int orderP,orderQ,order,num;
  for(int i=0;i<2;i++){
    R=P;
  	sort(R.begin(),R.end());
    order=0;
  	if(i==0)
      X=P;
    else
      X=Q;
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
      	if(X.at(j)==R.at(k)){
          num=k-j+1;
          break;
        }
      }
      if(num-1>0){
      	order+=(num-1)*kaijo(N-j-1);
      	for(int k=num+j;k>1;k--)
          swap(R.at(k-1),R.at(k-2));
      }
    }
    if(i==0)
      orderP=order;
    else
      orderQ=order;
  }
  cout<<abs(orderP-orderQ)<<endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ac_dir = {}
wa_dir = {}

for _ in range(m):
    p, s = input().split()
    if s == 'AC' and p not in ac_dir:
        ac_dir[p] = 1
    
    elif s == 'WA' and p not in wa_dir and p not in ac_dir:
        wa_dir[p] = 1
    
    elif s == 'WA' and p in wa_dir and p not in ac_dir:
        wa_dir[p] += 1

print(sum(ac_dir.values()), sum([k for j, k in wa_dir.items() if j in ac_dir]))

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

using namespace std;

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

   vector<int> d(n);
   for(int i=0;i<n;++i) cin >> d[i];

   sort(d.begin(),d.end());
   int answer = d[n/2] - d[n/2-1];

   cout << answer << endl;

   return 0;

}


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

using namespace std;

typedef long long ll;

#define REP(i,p,q) for(ll i = p; i < q; i++)

int main(void){
    REP(i,1,6){
        ll x;
        cin >> x;
        if(x == 0){
            cout << i << endl;
            break;
        } 
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define maxn 200001
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb(x) push_back((ll)(x))
#define pf(x) push_front((ll)(x))
#define nl cout << "\n";
 
void ini(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

int main(){
	ini();
	
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	ll sum=0;
	if(a>=k){
		sum+=k;
	}else if(a<k && b>=(k-a)){
		sum+=a;
	}else if(a<k && b<(k-a) && c>=(k-a-b)){
		sum+=a;
		sum-=(k-a-b);
	}

	cout <<sum;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    ll A , B;
    cin >> A >> B;
    ll N = gcd(A , B) , j = 1;
    for(ll i = 2; i * i < N; i++){
        if(N % i == 0){
            for(; N % i == 0; N /= i){
                
            }
            j++;
        }
    }
    if(N != 1){
        j++;
    }
    cout << j << endl;
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define PB push_back
#define pb push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len(stuff) (int) stuff.size()

#define int long long
#define float long double 
#define ll long long
#define ld long double

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const int inf = (int) 2e18;
const int upper = (int) 3e5 + 50;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

int arr[upper];
signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int a, b; cin >> a >> b;
	if (0 >= a and 0 <= b) {
		cout << "Zero";
	}
	else if (a > 0) {
		cout << "Positive";
	}
	else {
		a = -a;
		b = -b;
		swap(a, b);
		int cnt = b - a + 1;
		if (cnt & 1) cout << "Negative";
		else cout << "Positive";
	}
 	end_routine();		
}


Measured memory_bytes: 256
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var pmax = 0; var pmin = 1000000;
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var ary = Array.ConvertAll(line, int.Parse);
                pmax = Math.Max(ary.Sum(), pmax);
                pmin = Math.Min(ary.Sum(), pmin);
            }
            Console.WriteLine("{0} {1}", pmax, pmin);
        }
    }
}

Measured memory_bytes: 9604
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int a[Max],b[Max],n;
int lena=0,lenb=0,x;
struct node
{
    int len;
    int data;
    bool operator < (const node a)const{
        return a.len>len;
    }
};
int fun()
{
    priority_queue<node>ca,cb;
    int la=1,lb=1;
    sort(a,a+lena);
    sort(b,b+lenb);
    node t;
    for(int i=lena-1; i>=0; i--)
    {
        if(a[i]==a[i-1])
            la++;
        else
        {
            t.data=a[i];
            t.len=la;
            ca.push(t),la=1;
        }

    }
    for(int i=lenb-1; i>=0; i--)
    {
        if(b[i]==b[i-1])
            lb++;
        else
        {
            t.data=b[i];
            t.len=lb;
            cb.push(t),lb=1;
        }
    }
    if(ca.top().data==cb.top().data)
    {
        if(ca.top().len>cb.top().len)
        {
            cb.pop();
        }
        else if(ca.top().len<cb.top().len)
        {
            ca.pop();
        }
        else
        {
            node t;
            t.data=ca.top().data;
            t.len=ca.top().len;
            ca.pop();
            cb.pop();
            if(ca.top().len>cb.top().len)
                cb.push(t);
            else
                ca.push(t);
        }
    }
int ans1=0,ans2=0;
if(ca.size())
    ans1=ca.top().len;
if(cb.size())
    ans2=cb.top().len;
return n-ans1-ans2;
}
int main()
{

    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&x);
        if(i%2)
            a[lena++]=x;
        else
            b[lenb++]=x;
    }
    printf("%d\n",fun());
    return 0;
}


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

int main() {
  int is, in, nals[26] = {};
  char str[1200];
  while(fgets(str, sizeof(str), stdin) != NULL) {
    for(is = 0; is < strlen(str); ++is) {
      in = str[is] - ((str[is] >= 'a') ? 'a' : 'A');
      if(in >= 0 && in < 26) ++nals[in];
    }
  }
  for(in = 0; in < 26; ++in) printf("%c : %d\n", 'a' + in, nals[in]);
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    string o,e;
    cin >> o >>e;
    for(int i=0;i<o.size();i++){
        if(i!=e.size()) cout << o.at(i) <<e.at(i);
        else cout <<o.at(i);
    }
}


Measured memory_bytes: 256
public class Main
{
	public static void main(String args[])
	{
		java.util.Scanner sc=new java.util.Scanner(System.in);
		
		double h=sc.nextDouble();
		double a=sc.nextDouble();
		int x=(int)Math.ceil((h/a));
		System.out.println(x);
	}
}

Measured memory_bytes: 24532
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    char arr[n][m];
    int dp[n][m];

    for (int i=0 ; i<n ; i++){
        for (int j=0 ; j<m ; j++){
            cin >> arr[i][j];
            dp[i][j] = 0;

            if (arr[i][j] != '#'){
                if (i==0 && j==0){
                    dp[i][j] = 1;
                }
                else if (i==0 && j!=0){
                    dp[i][j] = dp[i][j-1]%MOD;
                }
                else if (i!=0 && j==0){
                    dp[i][j] = dp[i-1][j]%MOD;
                }
                else{
                    dp[i][j] = (((arr[i-1][j] != '#')*(dp[i-1][j]))%MOD + ((arr[i][j-1] != '#')*(dp[i][j-1]))%MOD)%MOD; 
                }
            }

        }
    }
    cout << dp[n-1][m-1]%MOD << "\n";
    return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
char a[1001][1001];
int v[1001][1001],n,h,w,sx,sy,ans;
int dir[4][2]={-1,0,1,0,0,1,0,-1};
char b[1001];
int s[1001][1001];
struct st
{
    int x,y;
}st1,st2,fl,pp;
int check(st kk)
{
    if(kk.x>=0&&kk.x<h&&kk.y>=0&&kk.y<w)
        return 1;
    else
    	return 0;
}
int  bfs(char c)
{
	queue<st>qq;	
	qq.push(pp);
    memset(v,0,sizeof(v));
    memset(s,0,sizeof(s));
    while(!qq.empty())
    {   	
		st1=qq.front();		
        qq.pop();
     	if(a[st1.x][st1.y]==c)
     	{
	     	pp=st1;			
			//printf("+%d %d+ %d\n",st1.x,st1.y,s[pp.x][pp.y]);	
	 		break;  
    	}             
        for(int i=0;i<4;i++)
        {
            st2.x=st1.x+dir[i][0];
            st2.y=st1.y+dir[i][1];
            if(check(st2)&&v[st2.x][st2.y]==0&&a[st2.x][st2.y]!='X')
            {
     			v[st2.x][st2.y]=1;
                s[st2.x][st2.y]=s[st1.x][st1.y]+1;
                //printf("-%d %d %d-\n",st2.x,st2.y,s[st2.x][st2.y]);
                qq.push(st2);
            }
        }
    }	
	return s[pp.x][pp.y];
   // printf("(%d %d %d %c)\n",st1.x,st1.y,s[st1.x][st1.y],c);
   
}
int main()
{
    int  i,j,k,m,l;
    while(~scanf("%d %d %d",&h,&w,&n))
    {    
    	getchar();
        memset(v,0,sizeof(v));
        memset(s,0,sizeof(s));
        for(i=0;i<h;i++)
        {
            scanf("%s",&a[i]);
        }
        for(i=0;i<n;i++)
        {
            b[i]=i+1+'0';
            //printf("%c\n",b[i]);
        }
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                if(a[i][j]=='S')
                {
                    pp.x=i;
                    pp.y=j;
                }
            }
        }
        //printf("%d %d\n",sx,sy);
        int sum=0;
		for(i=0;i<n;i++)
        { 
            sum+=bfs(b[i]);
            //printf("[%d]\n",sum);
        }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 9868
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;

unordered_set<char> m;

int main(void)
{
	int n;
	cin >> n;
	vector<int> vs(n);
	for (int i = 0; i < n; i++) {
		cin >> vs[i];
	}
	ll sum = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			sum += vs[i] * vs[j];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    string ans;
    if(a+b==15)ans="+";
    else if(a*b==15)ans="*";
    else ans="x";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  ll X;cin>>X;
  ll ans = 1000*(X/500) +5*((X%500)/5);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
ks = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))


res = 0
for i in range(2**n):
    on = [0 for _ in range(n)]
    for j in range(n):
        if((i>>j)&1):
            on[j]=1
    all_on = True 
    for j in range(m):
        on_num = 0 
        for s in ks[j][1: ]:
            if(on[s-1]==1):
                on_num += 1 

        if(on_num%2 != p[j]):
            all_on = False
            break 

    if(all_on):
        res += 1
print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
int fact(int n){
  int m;
  if (n == 0)
      return 1;
  m = fact(n - 1);    
  return n * m;       
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vlong a(n);
    vlong sum(n);
    rep(i,n){
        cin>>a[i];
        if(i==0){
            sum[i]=a[i];
        }
        else{
        sum[i]=sum[i-1]+a[i];
        }
    }
    long long min=9999999999,flag;
    rep(i,n){
        if(abs(sum[i]-(sum[n-1]-sum[i]))<min){
            min=abs(sum[i]-(sum[n-1]-sum[i]));
            flag=i;
        }
    }
    cout<<min<<'\n';
    return(0);
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    vector<int> ans;
    int pos;
    char left_hand[] = {'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'};
    while(true){
        int cnt = 0;
        pos = -1;
        string S; cin >> S;
        int lenS = S.length();
        if(lenS == 1 && S[0] == '#') break;
        rep(i, S.length()){
            char op = S[i];
            bool left = false; //0 -> right, 1 -> left
            rep(j, 15) if(op == left_hand[j]) left = true;
            if(pos == -1) pos = left;
            else if((pos == 0 && left) || (pos == 1 && !left)){
                cnt++;
                pos = !pos;
            }
            //cout << S[i] << ": " << left << endl;
        }
        ans.push_back(cnt);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}


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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   
    ll n;
    cin >> n;
    ll a[n];
    ll _xor = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        _xor ^= a[i];
    }
    for(int i = 0; i < n; i++){
        cout << (_xor ^ a[i]) << ' ';
    }
    return 0;
}
// Write Here


Measured memory_bytes: 5172
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()
    }
//    func enumerated() -> [(Int, Element)] {
//        return self.enumerate()
//    }
    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)!}
}
//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

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



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

let input = readIntSplit(by: " ")
let (A, P) = (input[0], input[1])
print((A*3+P)/2)


Measured memory_bytes: 7908
#include <stdio.h>

int main()
{
  int k;
  scanf("%d",&k);
  char s[101] = {0};
  scanf("%s",&s);
  int i;
  i = 0;
  while (s[i])
  {
    i++;
  }
  if (i <= k)
  {
    printf("%s",s);
  }
  else
  {
    i = 0;
    while (i < k)
    {
      printf("%c",s[i]);
      i++;
    }
    printf("...");
  }
}

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


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll i,j;
    string s1,s2;
    cin>>s1>>s2;
    ll n=s1.size()+1,m=s2.size()+1;
    ll dp[n][m];
    
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            
            else if(s1[i-1]==s2[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans="";
    i=n-1;j=m-1;
    while(i>0 && j>0)
    {
        if(dp[i][j]>dp[i-1][j] && dp[i][j]>dp[i][j-1])
        {
            ans=s1[i-1]+ans;
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 70656
#include<stdio.h>
int main(){
    int W,H,i,j;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0){
            break;
        }
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i==0 || i==H-1 || j==0 ||j==W-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
        printf("\n");
        }
    printf("\n");
    }
return 0;
}


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

constexpr int INF = 1e9+1;

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for(int i=0; i<N; ++i) {
        cin >> v[i] >> w[i];
    }
    vector<int> dp(10001, INF);
    dp[0] = 0;
    for(int i=0; i<N; ++i) {
        for(int j=10000; j>=v[i]; --j) {
            dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
        }
    }
    int res = 0;
    for(int i=10000; i>=0; --i) {
        if(dp[i] <= W) {
            res = i;
            break;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, k; cin >> n >> k;
    int maxE = (n-1) * (n-2) / 2;

    if (k > maxE) {
        cout << -1 << endl;
        return 0;
    }

    int m = n - 1;
    int rem = maxE - k;
    m += rem;

    vector<pii> ans;
    for (int i = 1; i < n; i++) ans.push_back({i, n});

    int u = 1, v = 2;
    for (int i = 0; i < rem; i++) {
        ans.push_back({u, v});
        v++;
        if (v == n) {
            u++;
            v = u+1;
        }
    }

    cout << m << endl;
    rep(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}


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

using namespace std;

int rasst(int a, int b, int c, int d)
{
    return abs(a - c) + abs(b - d);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, x = 0, y = 0, t = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int t1, x1, y1;
        cin >> t1 >> x1 >> y1;
        int c = rasst(x, y, x1, y1);
        if (t1 - t < c) cout << "No", exit(0);
        if ((t1 - t - c) % 2 == 1) cout << "No", exit(0);
        x = x1, y = y1, t = t1;
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256