akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const LL INF = (1ll << 60);


//変数
int N, M;
vector<LL> x, y, z;






//サブ関数
//入力
void input()
{
	cin >> N >> M;
	REP(i, N) {
		LL tmp;
		cin >> tmp; x.push_back(tmp);
		cin >> tmp; y.push_back(tmp);
		cin >> tmp; z.push_back(tmp);
	}
}

LL do_dp(vector<LL> sum) {
	
	vector<vector<LL>> dp(N + 1, vector<LL>(M + 1, -INF));
	REP(i, N+1) {
		dp[i][0] = 0;
	}
	for(int i = 1; i < N + 1; i++) {
		for (int j = 1; j < M + 1; j++) {
			//look left up
			if (dp[i - 1][j - 1] != -INF) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + sum[i]);
			}
			//look up
			if (dp[i - 1][j] != -INF) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			}
			if (dp[i][j] == -INF)break;
		}
	}

	return dp[N][M];
}

//計算
void calc()
{
	LL res = -INF;
	REP(i, 8) {
		bool a, b, c;
		int j = i;
		c = (j % 2);
		j /= 2;
		b = (j % 2);
		j /= 2;
		a = (j % 2);

		vector<LL> sum(N+1, 0);
		REP(i, N) {
			sum[i+1] += x[i] * (a ? 1 : -1);
		}
		REP(i, N) {
			sum[i+1] += y[i] * (b ? 1 : -1);
		}
		REP(i, N) {
			sum[i+1] += z[i] * (c ? 1 : -1);
		}
		res = max(res, do_dp(sum));
	}
	cout << res << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll k; cin>>k;
    int n = 50;
    vector<ll> ans(n);
    rep(i,50) ans[i] = 49+k/50;
    k %= 50;
    rep(i,k) {
        ans[i] += n;
        rep(j,n) if (i!=j) ans[j]--;
    }

    cout << n << '\n';
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)
#define SORT(a) sort((a).begin(),(a).end());
#define che(a,string) cout<<string<<":"<<(a)<<endl;
#define ch(a,string) cout<<string<<":"<<(a)<<" ";
using namespace std;
typedef pair<int,int> p;
int main(){
	int d,n;
	cin >>d>>n;
	 long long k= pow(100,d);
	 if(100==n){
		 cout<<k*n+k<<endl;
	   }
	   else{
	cout<<k*n<<endl;
		 }
	}


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

int main(){
    int N;
    cin >> N;
    int d[N];
    for(int i=0; i<N; ++i){
        cin >> d[i];
    }
    int res=0;
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            if(i!=j){
            res+=d[i]*d[j];
            }
        }
    }
    cout << res/2;            
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;

    vector<ll> w(n);

    NREP() {
        cin >> w[i];
    }

    ll ans = LONG_LONG_MAX;
    ll sum_before = 0;
    ll sum_after = 0;

    sum_before = w[0];
    NREP() {
        sum_after += w[i];
    }
    sum_after -= w[0];

    ans = abs(sum_after - sum_before);
    NREP() {
        if (i == 0) continue;

        sum_before += w[i];
        sum_after -= w[i];

        ans = min(ans, abs(sum_after - sum_before));
    }

    MSG(ans)
}



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

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

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

    map<string, int> mp1;
    set<string> ss;
    REP(i, n){
        string s;
        cin >> s;

        ss.insert(s);
        mp1[s]++;
    }

    int m;
    cin >> m;

    map<string, int> mp2;

    REP(i, m){
        string t;
        cin >> t;

        mp2[t]++;
    }

    int yen = 0;
    for (auto x : ss) 
        yen = max(yen, max(0, mp1[x] - mp2[x]));
    
    cout << yen << endl;
    
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc141/tasks/abc141_c
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int sum[100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> v(Q), score(N, K);
    REP(i, Q) {
        int t;
        cin >> t;
        sum[t - 1]++;
    }
    REP(i, N) {
        if (K - Q + sum[i] > 0) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }

    return 0;
}

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

int main(){
  string S; cin >> S;
  
  // >>...><...<<のセットで考える
  long long result=0;
  long long l=0, r=0;
  for(int i=0; i<S.size(); i++){
    (S[i]=='>'?l:r)++;
    
    if(i==S.size()-1){
      if(S[i]=='<'){
        result+=(r*(r+1)/2);
      }else{
        result+=(l*(l+1)/2);
        result-=min(l,r);
      }
    }else if(S[i]=='<'&&S[i+1]=='>'){
      result+=(r*(r+1)/2);
      l=0;
    }else if(S[i]=='>'&&S[i+1]=='<'){
      result+=(l*(l+1)/2);
      result-=min(l,r);
      r=0;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(13);
  for (int i = 0; i < n; i++) {
    int d; cin >> d;
    a[d]++;
  }
  if (a[0] or a[12] >= 2) cout << 0 << '\n';
  else {
    bool b = false;
    for (int i = 1; i < 12; i++) if (a[i] >= 3) b = true;
    if (b) cout << 0 << '\n';
    else {
      auto diff = [](int a, int b) { return min(abs(a - b), 24 - abs(a - b)); };
      auto calc = [&](V<>& v) {
        int res = 100, n = v.size();
        for (int i = 0; i < n; i++) {
          for (int j = i + 1; j < n; j++) res = min(res, diff(v[i], v[j]));
        }
        return res;
      };
      int res = 0;
      for (int i = 0; i < 1 << 11; i++) {
        V<> v = {0};
        if (a[12]) v.push_back(12);
        for (int j = 1; j < 12; j++) {
          if (a[j] >= 2) {
            v.push_back(j);
            v.push_back(-j);
          } else if (a[j]) {
            if (i & 1 << j - 1) v.push_back(j);
            else v.push_back(-j);
          }
        }
        res = max(res, calc(v));
      }
      cout << res << '\n';
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<list>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;

struct Node
{
    Node * right = nullptr;
    Node * left  = nullptr;
    int value;
};

int parseInt(string & str,int & i)
{
    int rtn=0;
    while(str[i]>='0'&&str[i]<='9')
    {
        rtn *= 10;
        rtn += (int)(str[i]-'0');
        ++i;
    }
    return rtn;
}

Node * makeTree(string & str,int & i)
{
    if(str[i]==')')return nullptr;
    Node * current = new Node;
    ++i; // (
    current->left = makeTree(str,i);
    ++i; // )
    ++i; // [
    current->value = parseInt(str,i);
    ++i; // ]
    ++i; // (
    current->right = makeTree(str,i);
    ++i; // )
    return current;
}

void output(Node * A,Node * B)
{
    cout << "(";
    if(A->left && B->left)
    {
        output(A->left,B->left);
    }
    cout << ")[";
    cout << A->value + B->value;
    cout << "](";
    if(A->right && B->right)
    {
        output(A->right,B->right);
    }
    cout << ")";
}


int main()
{
    string A,B;
    cin >> A >> B;
    int i=0;
    Node * ATree = makeTree(A,i);
    i=0;
    Node * BTree = makeTree(B,i);

    output(ATree,BTree);
    cout << endl;


    return 0;
}



Measured memory_bytes: 3216
using System;
using System.Linq;
using System.Text;

// フレームの描画

public class ITP1_5_B
{
    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        StringBuilder sb = new StringBuilder();
        while (true)
        {
            int[] nums = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int h = nums[0];
            int w = nums[1];
            if (h == 0 && w == 0)
            {
                break;
            }
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                    {
                        sb.Append("#");
                    }
                    else
                    {
                        sb.Append(".");
                    }
                }
                sb.AppendLine();
            }
            sb.AppendLine();
        }
        Console.Write(sb.ToString());
    }
}



Measured memory_bytes: 16316
#include<stdio.h>
int main(void)
{
	int n,i,j,k,cnt;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int X, t;
    while(scanf("%d %d",&X,&t)!=EOF){
        if(X>t)
        {
            printf("%d\n",(X-t));
        }
        else
        {
            printf("0\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = [int(input()) for _ in range(N)]
ans, temp = 0, 0
for i in range(N-1, -1, -1):
    if A[i] < temp:
        print(-1)
        exit() 
    elif A[i] != 0:
        if A[i] == temp:
            temp -= 1    
        else:
            if i  >= A[i]:
                ans += A[i]
                temp = A[i] - 1
            else:
                print(-1)
                exit()
print(ans)

Measured memory_bytes: 11052
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

ll INF = 1e18;
bool dp_x[20000][10000];
bool dp_y[20000][10000];
ll MID = 10000;
string s;
ll x,y;
vector<ll> vx,vy;

int main(){
    cin >> s;
    cin >> x >> y;
    ll count = 0;
    bool f = true;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'T'){
            if(f){
                vx.push_back(count);
                f = false;
            }else{
                vy.push_back(count);
                f = true;
            }
            count = 0;
            continue;
        }
        count++;
        if(i == s.size()-1){
            if(f){
                vx.push_back(count);
            }else{
                vy.push_back(count);
            }
        }
    }
    for(int i=0;i<20000;i++){
        for(int j=0;j<=vx.size();j++){
            dp_x[i][j] = false;
        }
        for(int j=0;j<=vy.size();j++){
            dp_y[i][j] = false;
        }
    }
    dp_x[MID + vx[0]][0] = true;
    if(vy.size() > 0) dp_y[MID + vy[0]][0] = dp_y[MID - vy[0]][0] = true;
    else dp_y[MID][0] = true;
    for(int i=1;i<vx.size();i++){
        for(int j=0;j<20000;j++){
            if(dp_x[j][i-1]){
                if(j+vx[i] < 20000) dp_x[j+vx[i]][i] = true;
                if(j-vx[i] >= 0) dp_x[j-vx[i]][i] = true;
            } 
        }
    }
    for(int i=1;i<vy.size();i++){
        for(int j=0;j<20000;j++){
            if(dp_y[j][i-1]){
                if(j+vy[i] < 20000) dp_y[j+vy[i]][i] = true;
                if(j-vy[i] >= 0) dp_y[j-vy[i]][i] = true;
            } 
        }
    }
    if(vy.size() == 0){
        if(y != 0) cout << "No" << endl;
        else{
            if(dp_x[MID+x][vx.size()-1]){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }            
        }
        return 0;
    }
    if(dp_x[MID+x][vx.size()-1] && dp_y[MID+y][vy.size()-1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


class UnionFind {
 vector<int> data;
 int num;
public:
 UnionFind(int size) : data(size, -1), num(size) { }
 bool unionSet(int x, int y) {
  x = root(x); y = root(y);
  if (x != y) {
   if (data[y] < data[x]) swap(x, y);
   data[x] += data[y]; data[y] = x;
   num--;
  }
  return x != y;
 }
 bool findSet(int x, int y) {
  return root(x) == root(y);
 }
 int root(int x) {
  return data[x] < 0 ? x : data[x] = root(data[x]);
 }
 int size(int x) {
  return -data[root(x)];
 }
 int numSet() {
  return num;
 }
};

void solve(){
    ll n;
    cin>>n;
    vec<P> a(n),b(n);
    REP(i,n) cin>>a[i].first,a[i].second=i;
    REP(i,n) cin>>b[i].first,b[i].second=i;
    sort(all(a));
    sort(all(b));
  
    UnionFind uni(n);
    bool flag=false;
    REP(i,n){
        if(a[i].first>b[i].first){
            cout<<"No"<<en;
            return;
        }
        if(i+1<n and a[i+1]<b[i]) flag=true;
     
        uni.unionSet(a[i].second,b[i].second);
    }

    if(uni.numSet()>=2 or flag) cout<<"Yes"<<en;
    else cout<<"No"<<en;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;cin>>x;
  int cnt=0;
  if(x>=100){
      while(1)
      {
        x=x-100;
        cnt++;          
        if(x<100)
        {
          if(x<=cnt*5)
            cout<<1;
          else
            cout<<0;
          break;
        }
      }
  }
    else
      cout<<0;
  }
  
      
    



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		if(a < 10 && b < 10) {
			System.out.println(a * b);
		}else {
			System.out.println(-1);
		}

	}

}

Measured memory_bytes: 23764
#include <cstdio>

#define MAX 100000

int main()
{
	int N;
	scanf("%d", &N);
	if(N/10==0){
		printf("Yes\n");
		return 0;
	}
	for(int i=2; i<=9; i++){
		if(N%i==0 && N/i<=9){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
A, B, C, X = 4.times.map{gets.to_i}
T = A + B + C

p (0..A).inject(0){|sum, i|
    (0..B).map {|j| sum += 1 if ((X - 500*i - 100*j) / 50).between?(0, C)}
    sum
}

Measured memory_bytes: 1788
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define YES cout << "YES" << endl
#define NO  cout << "NO"  << endl
#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 100100100
using namespace std;
typedef long long ll;

int main(){
  int n, m; cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  rep(i, 0, n)  cin >> a[i] >> b[i];
  rep(i, 0, m)  cin >> c[i] >> d[i];
  rep(i, 0, n){
    int checkPoint = 1;
    int closest = abs(a[i]-c[0])+abs(b[i]-d[0]);
    rep(j, 1, m){
      int dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(dist < closest) {
        closest = dist;
        checkPoint = j+1;
      }
    }
    cout << checkPoint << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep2(i,a,n) for(int i = (a);i < (n);i++)
#define rep(i,n) rep2(i,0,n)
#define INF (1LL << 60)

int main(void){
    int n;cin >> n;
    int a[n];rep(i,n)cin >> a[i];
    int sum = 0;
    for(int i = 0;i < n;i++){
        if((i+1) % 2 == 1 && a[i] % 2 == 1)sum++;
    }
    cout << sum;
}


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

namespace ABC144A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b,x;
            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            if (a >= 1 && b <= 9 && b >= 1 && a <= 9)
                x = a * b;
            else
                x = -1;
            Console.WriteLine(x);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int n,u,v,ans;
vector<int> adj[100001];
int dist2[100001];
void dfs1(int node,int p,int dist){
    dist2[node]=dist;
    for (auto i:adj[node]){
        if (i==p) continue;
        dfs1(i,node,dist+1);
    }
}
void dfs(int node,int p,int dist){
    if (dist>dist2[node]){
        ans=max(ans,dist-1);
    }
    for (auto i:adj[node]){
        if (i==p) continue;
        dfs(i,node,dist+1);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>u>>v;
    for (int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs1(u,-1,0);
    dfs(v,-1,0);
    cout<<ans;
}


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q, k;
	string s;
	cin>>n>>s>>q;
	REP(i, q){
		cin>>k;
		int sumd=0, summ=0;
		ll ans=0, sum=0;
		REP(j, k){
			if(s[j]=='D'){
				++sumd;
			}
			else if(s[j]=='M'){
				++summ;
				sum+=sumd;
			}
			else if(s[j]=='C'){
				ans+=sum;
			}
		}
		FOR(j, k, n){
			if(s[j-k]=='D'){
				--sumd;
				sum-=summ;
			}
			else if(s[j-k]=='M'){
				--summ;
			}
			if(s[j]=='D'){
				++sumd;
			}
			else if(s[j]=='M'){
				++summ;
				sum+=sumd;
			}
			else if(s[j]=='C'){
				ans+=sum;
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	string s;
	cin >> s;
	int k = 0,g = 0;

	int l = s.length();
	REP(i,l) {
		if((i+1) %2 == 1) {
			if(s[i] == 'L') {
				k += 1;
			}
		} else {
			if(s[i] == 'R') {
				g += 1;
			}
		}
	}
	if(k >= 1 || g >= 1) {
		cout << "No" << endl;
	} else {
		cout << "Yes" <<endl;
	}
}



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

a = [0,0,0,0]

for i in range(n):
  s = input()
  if s == "AC":
    a[0] += 1
  elif s== "WA":
    a[1] += 1
  elif s == "TLE":
    a[2] += 1
  else:
    a[3] += 1
print("AC x",a[0])
print("WA x",a[1])
print("TLE x",a[2])
print("RE x",a[3])

Measured memory_bytes: 9212
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 1, 0};


//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	REP(a, n){
		VS table(8);
		REP(i, 8){
			cin >> table[i];
		}
		int x, y;
		cin >> x >> y;
		queue<PII> q;
		x--;
		y--;
		q.push(MP(y, x));
		while(!q.empty()){
			PII p = q.front();
			q.pop();
			int x = p.second, y = p.first;
			table[y][x] = '0';
			REP(i, 4){
				for(int m = 1; 3 >= m; m++){
					int dx = x + DX[i] * m;
					int dy = y + DY[i] * m;
					if(0 <= dx && dx < 8 &&
					0 <= dy && dy < 8 &&
					table[dy][dx] == '1'){
						table[dy][dx] = '0';
						q.push(MP(dy, dx));
					}
				}
			}
		}
		cout << "Data " << a + 1 << ":" << endl;
		REP(i, 8){
			REP(j, 8){
				printf("%c", table[i][j]);
			}
			putchar('\n');
		}
	}
	
	return 0;
}

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


int s=0,h=0;

struct node
{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;


Node treeSearch(Node,int);
void insert(int);
void inorder(Node );
void preorder(Node);






#define NIL NULL

Node root;





void insert(int k)
{
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key<x->key)x=x->left;
      else  x=x->right;
    }

  z->parent=y;
  if(y==NIL)root=z;
  else
    {
      if(z->key < y->key)y->left=z;
      else y->right =z;
    }
}

void inorder(Node u)
{
  if(u==NIL)return;
  inorder(u->left);

  printf(" %d",u->key);
  inorder(u->right);
  s++;
}

void preorder(Node u)
{
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
 
}



int main()
{
  int n,i,x;
  char com[10];

  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    {
      scanf("%s",com);
     
      if(strcmp(com,"insert")==0)
	{
	  scanf("%d",&x);
	  insert(x);
	}
      else if(strcmp(com,"print")==0)
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	  
	}
      
    }

  return 0;
  
}



Measured memory_bytes: 25224
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
#define MOD 1000000007
using namespace std;
int main(){
    ll n,h,sum=0,a;
    cin>>h>>n;
    rep(i,0,n){
        cin>>a;
        sum+=a;
    }
    if(h<=sum)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n+1);
    rep(i, 0, n) cin >> h[i];
    h[n] = -1;
    ll mx = *max_element(h.begin(), h.end());
    ll ans = 0;
    rep(i, 1, mx+1){
        ll l = 0;
        ll r = 0;
        while(l < n+1){
            if(h[l] >= i){
                l++;
                r = 1;    
            }else{
                l++;
                ans += r;
                r = 0;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

bool check(int q, int i, int v, int A[], int n) {
	if (v == q)
		return true;

	if (i == n || v > q)
		return false;

	return check(q, i + 1, v, A, n) || check(q, i + 1, v + A[i], A, n);
}

int main() {

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

	int q;
	scanf("%d", &q);
	int m[q];
	for (int i = 0; i < q; ++i) {
		scanf("%d", &m[i]);
	}

	for (int i = 0; i < q; ++i) {
		if (check(m[i], 0, 0, A, n)) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

    string s;
    cin >> s;
    sort(s.begin(),s.end());
    
    if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])cout<<"Yes"<<endl;
    else cout << "No" <<endl;
  
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import copy
def main():
    N = int(input())
    A = [(int(i) - 1) for i in input().split()]
    ans = [0 for i in range(N)]
    for i in range(len(A)):
        ans[A[i]] += 1
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 33428
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	for _, r := range s {
		if string(r) == "," {
			fmt.Print(" ")
		} else {
			fmt.Print(string(r))
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 1776
def resolve():
    a, b, c = map(int, input().split())
    k = int(input())

    ans = 0
    while a >= b:
        b *= 2
        ans += 1
    while b >= c:
        c *= 2
        ans += 1
    if k>=ans:
        print("Yes")
    else:
        print("No")
resolve()

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

ll A, B;

ll solve(ll L, ll R){
    if(L == R){
        return 1;
    }
    for(int i = 60;i >= 0;i--){
        ll C = (1LL << i);
        if(R & C){
            if(L & C){
                L ^= C;
                R ^= C;
                continue;
            }else{
                ll tmp = C - L;
                ll v1 = R - C; 
                int bit = 64 - __builtin_clzll(v1);
                ll val = (1LL << bit) - 1;
                tmp += min(C, val + 1 + C - L);
                return tmp;
            }
        }
    }
    return 0;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> A >> B;
    if(A == B){
        cout << 1 << endl;
        return 0;
    }
    int bit = 0;
    for(bit = 60;bit >= 0;bit--){
        ll C = (1LL << bit);
        if((A >> bit & 1) != (B >> bit & 1)){
            break;
        }
    }
    A &= (1LL << bit + 1) - 1;
    B &= (1LL << bit + 1) - 1;
    ll c = bit - 1;
    while(c >= 0 and !(B >> c & 1))
        c--;
    c = 1LL << c + 1;
    ll mid = 1LL << bit;
    cout << mid - A + c + mid * 2 - max(mid + c, A | mid) << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
lst = [[0, 0] for i in range(n)]
correct = 0
wrong = 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == "WA":
        lst[p-1][0] += 1
    if s == "AC" and lst[p-1][1] == 0:
        correct += 1
        wrong += lst[p-1][0]
        lst[p-1][1] = 1
print(correct, wrong)

Measured memory_bytes: 13172
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            if (a % 2 == 1) {
                System.out.println("first");
                return;
            }
        }
        System.out.println("second");
    }
}

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

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

    int N;
    cin >> N;
    vector<int> v(N + 1);
    for (int i = 0, Pi; i < N; i++) {
        cin >> Pi;
        v[Pi] = i;
    }

    long long sum = 0;
    set<int> visited;
    for (int Pi = N; Pi >= 1; Pi--) {
        int i = v[Pi], a = -1, b = -1, x = N, y = N;
        visited.insert(i);
        set<int>::iterator it = visited.find(i);
        it++;
        if (it != visited.end()) {
            x = *it;
            it++;
            if (it != visited.end())
                y = *it;
            it--;
        }
        it--;
        if (it != visited.begin()) {
            it--;
            a = *it;
            if (it != visited.begin()) {
                it--;
                b = *it;
            }
        }
        sum += (long long) Pi * ((a - b) * (x - i) + (y - x) * (i - a));
    }
    cout << sum << '\n';

    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <cstdint>

using namespace std;

constexpr int64_t unknown = -1;
constexpr int64_t invalid = -2;
constexpr int64_t mod = 1000000007ll;

int64_t f(vector<int64_t> &memo, int n)
{
  if (memo[n] == unknown) 
  {
    memo[n] = 0;
    for (int i = 1; i <= 2; i++)
    {
      if (0 <= n - i && memo[n - i] != invalid)
      {
        memo[n] += f(memo, n - i);
        memo[n] %= mod;
      }
    }
  }
  return memo[n];
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int64_t> memo(n + 1, unknown);
  for (int i = 0; i < m; i++) 
  {
    int a;
    cin >> a;
    memo[a] = invalid;
  }
  memo[0] = 1;
  cout << f(memo, n) << endl;
}

Measured memory_bytes: 7296
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    s = input()

    p = s[0]
    for i in s[1:]:
        if i == p:
            print('Bad')
            return
        p = i

    print('Good')


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29932
#include<stdio.h>
 int main(void)
 {
    int A,B,C,a=0;

    scanf("%d%d%d",&A,&B,&C);

    if((A==5)||(A==7)){
      if((B==5)||(B==7)){
        if((C==5)||(C==7)){
          if(A+B+C==17) printf("YES\n");
            else printf("NO\n");
        }
      }
    }

 return 0;
 }

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	vector<vector<double>> dp(3001, vector<double>(3001));
	dp[0][0] = 1.;

	int n; read(n);
	vector<double> p(n + 1);
	rep(i, 1, n + 1) read(p[i]);

	cout << fixed << setprecision(20);

	rep(i, 1, n + 1) rep(j, 0, n + 1) {
		dp[i][j + 1] += dp[i - 1][j] * p[i];
		dp[i][j] += dp[i - 1][j] * (1 - p[i]);
	}

	double p0 = 0;
	rep(i, 0, n + 1) {
		if (i > n - i) {
			p0 += dp[n][i];
		}
	}

	die(p0);
}


Measured memory_bytes: 70784
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    unsigned N, r = 0;
    scanf("%u\n", &N);
    bool is_red[N];
    unsigned left_w[N];
    char tmp;
    scanf("%c", &tmp);
    is_red[0] = tmp == 'R';
    left_w[0] = (unsigned) !is_red[0];
    for (unsigned i = 1; i < N; i++){
        scanf("%c", &tmp);
        is_red[i] = tmp == 'R';
        left_w[i] = left_w[i-1];
        if(!is_red[i]) left_w[i]++;
    }
    unsigned answer = min(left_w[N-1], N - left_w[N-1]), candidate;
    for (int i = N-1; i > 0; i--){
        if(is_red[i]) r++;
        if(candidate = max(left_w[i-1], r); answer > candidate)answer = candidate;
    }
    printf("%u\n", answer);
	return 0;
}

Measured memory_bytes: 2616
while 1:
    n=int(input())
    if n==0:break
    a,i,c=[0]*n,0,0
    x=input()
    for b in x:
        if b=='S':a[i],c=0,c+a[i]+1
        elif b=='L':a[i],c=a[i]+c+1,0
        else:a[i]+=1
        i=(i+1)%n
    print(' '.join(map(str,sorted(a))),c)

Measured memory_bytes: 7704
// Bismillahir Rahmanir Rahim
// AtCoder-b

#include<bits/stdc++.h>
using namespace std;
long long sum = 0;

int main(){
	int n,m,num;
	cin>>n>>m;
	for(int i = 0; i < m; ++i)
	  cin>>num,sum += num;
	  
	  if(n < sum)
	  cout<<-1<<endl;
	  else cout<<n - sum<< endl;
	return 0;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            long a = Long.parseLong(strArr[0]);
            long b = Long.parseLong(strArr[1]);
            long x = Long.parseLong(strArr[2]);
            long tmp1 = b / x;
            long tmp2 = a / x;
            long tmp3 = 0;
            if (a % x == 0) {
            	tmp3++;
            }
            System.out.println(tmp1 - tmp2 + tmp3);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

int main() {
    int N;
    cin >> N;
    vector <long long> a(N + 1);
    rep (i, N) cin >> a[i + 1];
    rep (i, N) a[i + 1] += a[i];

    long long ans = 1e18;
    range (i, 1, N) ans = min(ans, abs(a[i] - (a[N] - a[i])));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()

def main():
    N=ii()
    A = list(mi())

    xsum = A[0]
    for a in A[1:]:
        xsum ^=a

    ans = []
    for a in A:
        ans.append(xsum^a)

    print(*ans,sep=' ')


if __name__ == "__main__":
  main()

Measured memory_bytes: 112068
#include<stdio.h>


int main()
{
  int hira,sawa,i,j,ryo=0,f,g,h;
  scanf("%d",&hira);
  int x[hira];
  char c[12];
  for(i=0;i<hira;i++){
    scanf("%s %d",c,&sawa);
    if(c[0]=='i'){
      x[i]=sawa;
    }
    else if(c[6]=='F'){
      i-=2;hira-=2;
    }
    else if(c[6]=='L'){
      i--;hira--;ryo++;
    }
    else{
      i--;hira--;
      f=0;
      for(j=i;j>=0;j--){
	if(f>0)break;
	if(sawa==x[j]){
	  h=0;
	  g=i-j;
	  f++;
	  while(g!=h++)x[j+h-1]=x[j+1+h-1];
	  i--;hira--;
	}
      }
    }
  }
  for(i=0;i<hira-ryo;i++){
    if(i==hira-ryo-1)printf("%d\n",x[hira-1-i]);
    else printf("%d ",x[hira-1-i]);
  }
  return 0;
}

Measured memory_bytes: 4808
#include<stdio.h>
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2],R[MAX / 2 + 2],count = 0;

void merge(int a[],int n,int left,int mid,int right){
  int i,j,k,n1,n2;

  n1 = mid - left;
  n2 = right - mid;

  for(i = 0;i < n1;i++){
    L[i] = a[left + i];
  }

  for(i = 0;i < n2;i++){
    R[i] = a[mid + i];
  }

  L[n1] = R[n2] = SENTINEL;
  i = j = 0;

  for(k = left;k < right;k++){
    count++;
    if(L[i] <= R[j]){
      a[k] = L[i++];
    }
    else{
      a[k] = R[j++];
    }
  }
}

void mergeSort(int a[],int n,int left,int right){
  int mid;

  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(a,n,mid,right);
    mergeSort(a,n,left,mid);
    merge(a,n,left,mid,right);
  }
}

int main(){
  int a[MAX],n,i;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);

    if(a[i] >= SENTINEL){
      return 1;
    }
  }

  mergeSort(a,n,0,n);

  for(i = 0;i < n;i++){
    if(i > 0) printf(" ");
    printf("%d",a[i]);
  }
    printf("\n");

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

  return 0;
}


Measured memory_bytes: 5604
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n  # 根のノードは限らないので注意

    def find(self, x):  # あるノードの親を探すためのメソッド
        if self.parents[x] < 0:  # 親の場合、要素の個数を負の値で保持している
            return x  # 自身が親であるということ
        else:
            self.parents[x] = self.find(self.parents[x])  # 再帰的に親を探しにいく
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)  # この変数xに格納されているものは必ず根のノード
        y = self.find(y)  # この変数yに格納されているものは必ず根のノード
        if x == y:
            return  # もし同じ親ならば何も起こらない

        if self.parents[x] > self.parents[y]:  # それぞれ、要素の個数が負で格納されている
            # yのグループの方が要素が多いの場合（yの方が値が小さいということは、負の世界では値が大きいため）
            x, y = y, x  # 必ずxの方が要素が多い状態にする

        self.parents[x] += self.parents[y]  # 負の値だが、これでいい
        self.parents[y] = x  # yは親ではなくなったため、新しい親であるxの値を正でもつ

    def size(self, x):
        return -self.parents[self.find(x)]  # 親まで辿ればグループの大きさが負で格納されているため、それにマイナスをつけてreturnする

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 親が同じならTrueが返却される

    def members(self, x):  # この実装変じゃね？
        root = self.find(x)  # 親の値を取得する
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_counts(self):
        return len(self.roots())  # グループの数を返す

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}  # 親のノード番号をキーにして、子のノードを対応させた辞書を返す

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.union(x, y)

print(uf.group_counts())


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

int main() {
	int a, b;
	cin >> a >> b;
	string s;
	int ans = 0;
	for (int i = a; i <= b; i++) {
		s = to_string(i);
		if (s[0] == s[4] && s[1] == s[3]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(void)
{
  int a, b;
  cin >> a >> b;
  
    for(int i = 0; i < a * 2 - 1; i++)
    {
      cout << b - a + 1 + i;
      if(i < a * 2 - 2)
        cout << " ";
    }
  cout << endl;
}

Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A = [lr() for _ in range(3)]
N = ir()
bool = [[False] * 3 for _ in range(3)]
for _ in range(N):
    b = ir()
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bool[i][j] = True

answer = False
for i in range(3):
    if sum(bool[i]) == 3:
        answer = True
for j in range(3):
    cur = 0
    for i in range(3):
        if bool[i][j] == True:
            cur += 1
    if cur == 3:
        answer = True

if bool[0][0] + bool[1][1] + bool[2][2] == 3:
    answer = True
if bool[2][0] + bool[1][1] + bool[2][0] == 3:
    answer = True

print('Yes' if answer else 'No')


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

#define BUF_SIZE 52

struct point {
  int x;
  int y;
};

struct point dict[4] = {
  {-1, 0}, {1, 0},
  {0, -1}, {0, 1},
};

int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int row, col;
  sscanf(line, "%d %d", &row, &col);



  int i, j, k;
  char map[BUF_SIZE][BUF_SIZE];
  for(i = 0; i < BUF_SIZE; i++) {
    for(j = 0; j < BUF_SIZE; j++) {
      map[i][j] = 0;
    }
  }
  for(i = 1; i <= row; i++) {
    if(!fgets(line, BUF_SIZE, fp)) return 0;
    char *buf;
    int s;
    for(buf = line, s = 1; *buf != '\n'; buf++, s++) {
      map[i][s] = (*buf == '#');
    }
  }

  for(i = 1; i <= row; i++) {
    for(j = 1; j <= col; j++) {
      if(!map[i][j]) continue;
      int flag = 0;
      for(k = 0; k < 4; k++) {
        flag |= map[i+dict[k].x][j+dict[k].y];
      }
      if(!flag) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");

  return 0;
}

Measured memory_bytes: 128