akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <bitset>

using namespace std;
typedef long long LL;
const int maxn = 200005;

int ehead[maxn],ecnt;
struct edge {
	int u,v,w,next;
}edg[maxn];
void add(int u,int v,int w) {
	edg[++ecnt]=(edge){u,v,w,ehead[u]};
	ehead[u]=ecnt;
	edg[++ecnt]=(edge){v,u,w,ehead[v]};
	ehead[v]=ecnt;
}

int n,m,rt,cnt[maxn],sz[maxn],fa[maxn],faw[maxn];
void dfs(int u) {
	for (int v,j=ehead[u];j;j=edg[j].next)
	if ((v=edg[j].v)!=fa[u]) {
		fa[v]=u;faw[v]=edg[j].w;
		dfs(v);sz[u]+=sz[v];
		cnt[u]=max(cnt[u],sz[v]);
	}
	sz[u]++;cnt[u]=max(cnt[u],n-sz[u]);
	if (cnt[u]<=n/2&&!rt) rt=u;
}
int main()
{
	#ifdef Amberframe
		freopen("agc018d.in","r",stdin);
		freopen("agc018d.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int u,v,w,i=1;i<n;i++)
		scanf("%d %d %d",&u,&v,&w),add(u,v,w);
	dfs(1);LL ans=0;
	for (int i=2;i<=n;i++)
		ans+=2ll*faw[i]*min(sz[i],n-sz[i]);
	if (fa[rt]&&cnt[fa[rt]]<=n/2)
		printf("%lld",ans-faw[rt]);
	else {
		int minw=1<<30;
		for (int j=ehead[rt];j;j=edg[j].next)
			minw=min(minw,edg[j].w);
		printf("%lld",ans-minw);
	}
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

int pow2check(int x){
    int temp=1;
    while(temp<x){
        temp*=2;
    }
    if(temp==x){
        return 1;
    }else{
        return 0;
    }
}

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


    if(pow2check(N)){
        cout<<"No"<<endl;
        return 0;
    }
    
    int temp=1;
    while(temp*2<N){
        temp*=2;
    }
    
    if(N%2==1){
        cout<<"Yes"<<endl;
        cout<<1<<" "<<2<<endl;
        cout<<2<<" "<<3<<endl;
        cout<<3<<" "<<N+1<<endl;
        cout<<N+1<<" "<<N+2<<endl;
        cout<<N+2<<" "<<N+3<<endl;

        for(int i=4; i<=N; i+=2){
            cout<<i<<" "<<i+1<<endl;
            cout<<i+1<<" "<<1<<endl;
            cout<<1<<" "<<N+i<<endl;
            cout<<N+i<<" "<<N+i+1<<endl;
        }
       
    }else{
        //2^n, 2^n+1, 2^n+2を構成したらいける
        cout<<"Yes"<<endl;
        cout<<temp<<" "<<temp+1<<endl;
        cout<<temp+1<<" "<<1<<endl;
        cout<<1<<" "<<N+temp<<endl;
        cout<<N+temp<<" "<<N+temp+1<<endl;
        cout<<N+temp+1<<" "<<N+1<<endl;
        
        cout<<N+temp<<" "<<N+2<<endl;
        cout<<N+2<<" "<<temp+2<<endl;
        cout<<N+temp<<" "<<N+temp+2<<endl;
        cout<<N+temp+2<<" "<<2<<endl;
        
        cout<<N+temp+2<<" "<<N+3<<endl;
        cout<<1<<" "<<3<<endl;

        

        for(int i=4; i<=temp-1; i+=2){
            cout<<i<<" "<<i+1<<endl;
            cout<<i+1<<" "<<1<<endl;
            cout<<1<<" "<<N+i<<endl;
            cout<<N+i<<" "<<N+i+1<<endl;
        }
        
        for(int i=temp+3; i<=N; i+=2){
            //cout << "i^i+1 = " << (i^(i+1))<<endl;
            cout<<i+1<<" "<<i<<endl;
            cout<<i<<" "<<(i^(i+1))<<endl;
            cout<<(i^(i+1))<<" "<<N+i+1<<endl;
            cout<<N+i+1<<" "<<N+i<<endl;
        }
 
    }
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  int n;

  int tensu[200];

  while(cin>>n,n){
	//cout << n << endl;//
	int max = 0;
	int min = 1000;
	int sum=0;
	REP(i,n){
	  cin >> tensu[n];
	  sum+=tensu[n];
	  if(max<tensu[n])
		max=tensu[n];
	  if(min>tensu[n])
		min=tensu[n];
	}

	//cout<<min<<endl<<max<<endl<<sum<<endl;//

	cout << (sum-max-min)/(n-2) << endl;

  }

}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
using namespace std;
typedef pair<int,int>P;
#define pb push_back

map <int, vector<P> >MP;
set<P> MAS;


void Write(int a,int b){
	while(b>0){
		set<P>::iterator it=MAS.begin();
		if((*it).second - (*it).first + 1 <= b){
			MP[a].pb((*it));
			b-=((*it).second - (*it).first + 1);
			MAS.erase(it);
		}
		else{
			P t=(*it);
			MP[a].pb(P(t.first,t.first+b-1));
			MAS.erase(it);
			MAS.insert(P(t.first+b,t.second));
			b=0;
		}
	}
}

void Delete(int a){
	for(int i=0;i<MP[a].size();i++){
		MAS.insert(MP[a][i]);
	}
	MP[a].clear();
}

void Read(int a){
	map<int, vector<P> >::iterator it =MP.begin();
	for(;it != MP.end();it++){
		for(int i=0;i<(*it).second.size();i++){
			if((*it).second[i].first <= a && a <= (*it).second[i].second ){
				cout<<(*it).first<<endl;
				return;
			}
		}
	}
	cout<<-1<<endl;
}


int main(){
	int n;
	while(cin>>n,n){
		MP.clear();
		MAS.clear();
		MAS.insert(P(0,1000000000));
		
		char c;
		for(;n;n--){
			cin>>c;
			if(c=='W'){
				int a,b;
				cin>>a>>b;
				Write(a,b);
			}
			if(c=='D'){
				int a;
				cin>>a;
				Delete(a);
			}
			if(c=='R'){
				int a;
				cin>>a;
				Read(a);
			}
			if(c=='Q')n=1;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 21660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	char* N = new char[200002];
	cin >> N;
	char* p = N;
	ll c = 0;
	while(*p != '\0') {
		c += (*p) - 48;
		p++;
	}

	if (c % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return(0);
}


Measured memory_bytes: 3788
#include <stdio.h>

int main(void) {
	int H, W, i, j;
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 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: 2032
package main

import (
  "fmt"
)

func main() {
  var n int 
  fmt.Scan(&n)
  h := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&h[i])
  }
  m := 0
  cnt := 0
  for _, x := range h {
    if x >= m {
      cnt++
      m = x
    }
  }
  fmt.Println(cnt)
}

Measured memory_bytes: 512
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    writeln(N == 1 && M == 1 ? 1 : N == 1 ? max(0, M-2) : M == 1 ? max(0, N-2) : (N-2) * (M-2));
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] res = new int[26];
            Arrays.fill(res, 0);
            int n = in.nextInt();
            for (int i = 0; i < n; ++i) {
                char[] arr = in.next().toCharArray();
                int[] amount = new int[26];
                Arrays.fill(amount, 0);
                for (char x : arr) amount[x - 'a']++;
                for (int k = 0; k < 26; ++k) {
                    res[k] = i == 0 ? Math.max(res[k], amount[k]) : Math.min(res[k], amount[k]);
                }
            }
            StringBuilder sb = new StringBuilder();
            char cur = 'a';
            for (int x : res) {
                for (int i = 0; i < x; ++i) sb.append(cur);
                ++cur;
            }
            out.println(new String(sb));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22868
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int x, a, b;

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	scanf("%d%d%d", &x, &a, &b);
	if(abs(x - a) < abs(x - b)){
		printf("A\n");
	}else{
		printf("B\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;

int N,K,cnt[101];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>K;
    for(int i=0;i<K;i++){
        int d; cin>>d;
        for(int j=0;j<d;j++){
            int t; cin>>t;
            if(cnt[t]==0) N--;
            cnt[t]++;
        }
    }
    cout<<N;
    return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const int MOD=1e9+7;


struct UnionFind {
private:
  int N;
  // parは親要素、rancは階層、cntはそのTree内に含まれる要素数
  vector<int> par,ranc,cnt;
  
public:
  UnionFind(int N) : N(N),par(N),ranc(N,0),cnt(N,1) { REP(i,N) par[i]=i; }
  
  int memsiz(int s) { return cnt[root(s)]; }
  
  int root(int s) { return (par[s]==s) ? s : root(par[s]); }
  
  bool same(int x, int y) { return root(x)==root(y); }
  
  bool connected() {
    int base = root(0);
    REP(i,N) if (root(i)!=base) return false;
    return true;
  }
  
  void merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x==y) return;
    if (ranc[x]>ranc[y]) {
      par[y] = x;
      cnt[x] += cnt[y];
    } else {
      par[x] = y;
      cnt[y] += cnt[x];
      if (ranc[x]==ranc[y]) ranc[y]++;
    }
  }
};

int main() {
  ll N,M;cin>>N>>M;
  vector<P> bridges(M);
  REP(i,M) {
    int a,b;cin>>a>>b;
    a--;b--;
    bridges[i] = {a,b};
  }
  reverse(ALL(bridges));
 
  UnionFind uf(N);
 
  vector<ll> ans;
  ll tmp = N*(N-1)/2;
  REP(i,M) {
    ans.push_back(tmp);
    P bridge = bridges[i];
    if (uf.same(bridge.first,bridge.second)) continue;
 
    tmp -= uf.memsiz(bridge.first)*uf.memsiz(bridge.second);
    uf.merge(bridge.first, bridge.second);
  }
  reverse(ALL(ans));
  REP(i,M) OUT(ans[i]);

  return 0;
}

Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;

int a[3][3];
bool b[3][3];
bool bingo(){
    if((b[0][0]&&b[0][1]&&b[0][2])||(b[1][0]&&b[1][1]&&b[1][2])||(b[2][0]&&b[2][1]&&b[2][2])||(b[0][0]&&b[1][0]&&b[2][0])||(b[0][1]&&b[1][1]&&b[2][1])||(b[0][2]&&b[1][2]&&b[2][2])||(b[0][0]&&b[1][1]&&b[2][2])||(b[2][0]&&b[1][1]&&b[0][2])){
        return true;
    }
    else{
        return false;
        }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    rep(i,0,3){
        rep(j,0,3){
            cin>>a[i][j];
        }
    }
    int n,d;
    cin>>n;
    memset(b,0,sizeof(b));
    rep(i,0,n){
        cin>>d;
        rep(l,0,3){
            rep(j,0,3){
                if(d==a[l][j]){b[l][j]=1;}
            }
        }
    }
    cout<<(bingo()?"Yes":"No")<<endl;
}

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

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

  vector<vector<bool>> graph(n,vector<bool>(n,false));
  vector<P> edge(m);

  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    graph[a][b] = true;
    graph[b][a] = true;
    edge[i] = make_pair(a,b);
  }

  //全ての辺について、取り除いてBFSして橋かどうか調べる
  int ans = 0;
  for(auto p : edge){
    vector<bool> visited(n,false);

    //対象となる辺だけ取り除く
    int a = p.first;
    int b = p.second;
    graph[a][b] = false;
    graph[b][a] = false;

    queue<int> q;
    q.push(0);
    visited[0] = true;

    //つながっている頂点ぜんぶ訪れる
    while(!q.empty()){
      int now = q.front();
      q.pop();
      
      rep(i,n){
        if(graph[now][i]==false) continue;
        if(visited[i]==true) continue;

        q.push(i);
        visited[i] = true;
      }

    }

    //橋だったかどうか調べる
    for(auto i : visited){
      if(i==false){
        ans++;
        break;
      }
    }

    //辺を元に戻す
    graph[a][b] = true;
    graph[b][a] = true;

  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

const ll md = 998244353;

const int lim = 1e6+1;

ll mpow(ll a, ll e = md-2){
	ll res = 1;
	do {
		if(e & 1) res = res * a % md;
		a = a * a % md;
	} while(e >>= 1);
	return res;
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	vector<ll> phi(lim);
	rep(i,1,lim) phi[i] = mpow(i);
	vector<vi> divs(lim);
	rep(i,1,lim){
		for(int j = i; j < lim; j += i)
			divs[j].push_back(i);
	}
	rep(i,1,lim) trav(d, divs[i]) if(d < i)
		phi[i] = (phi[i]-phi[d])%md;
	vector<ll> s1(lim), s2(lim);
	
	int n;
	cin >> n;
	vi cnts(lim);
	rep(_,0,n){
		int a;
		cin >> a;
		++cnts[a];
	}
	rep(i,0,lim) if(cnts[i]){
		trav(d, divs[i]){
			s1[d] = (s1[d] + cnts[i] * (ll)i) % md;
			s2[d] = (s2[d] + cnts[i] * mpow(i,2)) % md;
		}
	}

	ll half = (md+1)/2;
	ll ans = 0;
	
	rep(d,1,lim){
		ll cur = phi[d] * (mpow(s1[d],2)-s2[d]);
		ans = (ans + cur) % md;
	}
	ans = ans * half % md;
	if(ans < 0) ans += md;
	cout << ans << endl;
}


Measured memory_bytes: 142208
//Code by : Abhishek Tiwari
//codechef.com/users/devil_within || hackerearth.com/@devil_within
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repr(i,a,b) for(int i=(a);i>(b);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pii pair<int,int> 
#define ff first
#define ss second 
#define mod 1000000007
#define inf 1000000000
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
using namespace std;

/*******************************************************************************************/
/*******************************************************************************************/
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { 
    os<<"["; for(int i=0;i<v.size()-1; ++i)os<<v[i]<<", ";os<<v[v.size()-1]<<"]\n"; return os; 
} 
template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { 
    os<<"{"; for(auto it : v) { os<<it; if(it!=*v.rbegin()) os<<", "; } os<<"}\n"; 
    return os; 
}
template <typename T, typename S> ostream& operator<<(ostream& os, const map<T, S>& v) { 
    os<<"{"; for(auto it:v){ os<<"("<<it.first<<" : "<<it.second<<")"; if(it!=*v.rbegin()) os<<", "; } os<<"}\n"; 
    return os; 
}
template <typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S>& v) { 
    os<<"("; os<<v.first<<", "<< v.second<<")"; 
    return os; 
} 
template<typename T> T maxi(T a,T b){return a>b ? a:b;}
template<typename T> T mini(T a,T b){return a<b ? a:b;}
/*******************************************************************************************/
/*******************************************************************************************/
int fpow(int x, int y, int p); 
int solve(int i , int j , vector<int> &a , int sum , vector<vector<int>> &dp)
{
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(i==j)
    {
        dp[i][i] = a[i];
        return dp[i][i];
    }
    
    int v1 = sum - solve( i +1 , j , a , sum - a[i] , dp);
    int v2 = sum - solve( i , j-1 , a , sum - a[j] , dp);
    dp[i][j] = max( v1 , v2);
    return dp[i][j];
}

int32_t main()  
{
#ifndef ONLINE_JUDGE
//freopen("input.txt" , "r" , stdin);freopen("output.txt" , "w" , stdout);freopen("error.txt" , "w" , stderr);
#endif
fio;
int tcases = 1;
//cin>>tcases;
for(int tcase = 1 ; tcase <= tcases ; ++tcase)
{
    int n;
    cin>>n;
    vector<int>a(n);
    rep( i, 0, n) cin>>a[i];
    vector<vector<int>> dp(n);
    rep(i , 0 , n) dp[i].resize(n , -1);
    int sum  = accumulate( a.begin() , a.end() , 0LL);
    int f = solve(0 , n-1 , a , sum , dp);
    int s = sum - f;
    cout<< f - s <<"\n";
    //cout<<"Case #"<<tcase<<": ";
}
return 0;
}



//Functions 

int fpow(int x, int y, int p) { 
    int res = 1; 
   x = x % p;  
   while (y > 0) { 
     if (y & 1) 
        res = (res * x) % p; 
     y = y >> 1; 
        x = (x * x) % p; 
    } 
    return res; 
} 



Measured memory_bytes: 70912
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;



#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 5e5 + 120;

string S , T;

int main(){FAST;    
    cin >> S >> T;

        for (int i = 0; i < S.size(); i++) {
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
        rotate(S.begin(), S.begin() + 1, S.end());
    }
    cout << "No" << endl;
    

    return 0;
}
 










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

#undef DBG

int main()
{
        int souwa;
        int  inputc;
        char numbuff[100000+1];
        long long int numbers[1000];
        int numnum;
        long long int i,j;
        long long int N, A, B, C, D;

        j = 0;

        numnum = 0;
        j = 0;
        while( (inputc = getc(stdin)) != EOF ) {
                if( inputc == ' ' || inputc == '\n' ) {
                        numbuff[j]  = '\0';
                        numbers[numnum++] = atoll(numbuff);
                        j=0;
                        continue;
                }
                else {
                        numbuff[j++] = inputc;
                }
        }

        N = numbers[0];
        A = numbers[1];
        B = numbers[2];
#ifdef DBG
        printf("%lld\n", LLONG_MAX );
        printf("N=%lld A=%lld B=%lld \n", N, A, B );
#endif

        int densha, tax;
        densha = N*A;
        if( N*A >= B ) {
                printf("%lld\n", B);
        } else {
                printf("%lld\n", N*A);
        }


        return 0;

}


Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
			int H=sc.nextInt();
			int W=sc.nextInt();
			String A[]=new String[H];
			String tmp;
			for(int i=0;i<H;i++) {
				A[i]="#"+sc.next()+"#";
				
			}
			String v="##";
			for(int i=0;i<W;i++) {
				v=v+"#";	
			}
			
			
			
			p(v);
			for(int h=0;h<H;h++) {
				System.out.println(A[h]);
			}
			p(v);
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21972
N,M=map(int,input().split())
A=[list(input()) for i in range(N)]
B=[list(input()) for i in range(M)]

ans=0
flag=0

for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j]==B[0][0]:
            for k in range(0,M):
                for l in range(0,M):
                    if A[i+k][j+l]==B[k][l]:
                        ans+=1
                        if ans==M**2:
                            flag=1
                    else:
                        ans=0
                        break
    
print("Yes" if flag else "No")
                

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		sc.nextLine();
		
		double sum = 0;
		for (int i = 0; i < N; i++) {
			final String s = sc.nextLine();
			final String[] split = s.split(" ");
			final double x = Double.parseDouble(split[0]);
			final String type = split[1];
			
			if (type.equals("JPY")) {
				sum += x;
			} else if (type.equals("BTC")) {
				sum += (double) 380000 * x;
			}
		}
		
		System.out.println(sum);
	}

}

Measured memory_bytes: 21204
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();

    int[] dp = new int[N + 1];
    for (int i = 1; i <= N; i++) {
      dp[i] = dp[i - 1];
      if (a[i - 1] == dp[i - 1] + 1) dp[i]++;
    }
    if (dp[N] == 0) System.out.println(-1);
    else System.out.println(N - dp[N]);
  }
}


Measured memory_bytes: 79540
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

ll gcd(ll a, ll b) {
	ll temp;
	while (a % b != 0)
	{
		temp = b;
		b = a % b;
		a = temp;
	}
	return b;
}

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

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

	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];

	int mcnt = 0;
	int mm = INF;
	ll ans = 0;
	rep(i, n) {
		if (abs(a[i]) < mm) {
			mm = abs(a[i]);
		}
		if (a[i] < 0) {
			mcnt++;
		}
		ans += abs(a[i]);
	}
	//cout << mm << endl;
	if (mcnt % 2 != 0) {
		ans -= mm*2;
	}

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



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

int main(){
	int N, K; cin>>N>>K;
	vector<int> A(N); rep(i, N) cin>>A[i];
	int ng = 0, ok = 1e9; // (ng,ok] = (l,r]
	while(ok - ng > 1){
		auto f = [&](int m){
			int64_t c = 0;
			rep(i, N) c += (A[i] - 1) / m;
			return c <= K;
		};
		int m = (ok + ng) / 2;
		if(f(m)) ok = m; else ng = m;
	}
	cout<< ok <<endl;
}


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

ll pmod(ll i, ll n) {
    return (i % n + n) % n;
}

int main() {
    ll n,k;
    cin >> n >> k;
    unordered_map<ll,ll> diff;
    ll cumsum[n+1]; cumsum[0] = 0;
    ll a; 
    forr(i,0,n) {
        cin >> a;
        cumsum[i+1] = pmod(cumsum[i] + a,k);
    }
    ll low = 1;
    ll high = min(n+1,k);
    forr(i,1,high) {
        if (diff.find(pmod(cumsum[i]-i,k)) == diff.end()) 
            diff[pmod(cumsum[i]-i,k)] = 1;
        else diff[pmod(cumsum[i]-i,k)] += 1;
    }
 
    ll count = 0;
    forr(i,0,n) {
        if (diff.find(pmod(cumsum[i]-i,k)) != diff.end())
            count += diff[pmod(cumsum[i]-i,k)];
        
        diff[pmod(cumsum[low]-low,k)] -= 1;
        low += 1;
        if (high !=n+1) {
            if (diff.find(pmod(cumsum[high]-high,k)) != diff.end())
                diff[pmod(cumsum[high]-high,k)] += 1;
            else diff[pmod(cumsum[high]-high,k)] = 1;
            high += 1; 
        } 
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 10056
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  int M, K;
  cin >> M >> K;
  if(K > ((1 << M) - 1)) {
    cout << -1 << endl;
    return 0;
  }

  if(M == 0) {
    cout << "0 0" << endl;
    return 0;
  }

  if(M == 1) {
    if(K == 1) cout << -1 << endl;
    else cout << "0 1 1 0" << endl;
    return 0;
  }

  cout << K << " ";
  for(int i = 0;i < (1 << M);i++) {
    if(i != K) cout << i << " ";
  }
  cout << K << " ";
  for(int i = ((1 << M) - 1);i >= 0;i--) {
    if(i != K) cout << i << " ";
  }

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
	long long int a;
	long long int b;
	long long int c;
	cin >> a;
	b=a/11*2;
	c=a%11;
	if(0<c&&c<=6){
		b+=1;
	}else if(c>6){
		b+=2;
	}
	cout <<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n;

int main() { 

  cin >> n;
  cout << (n + 1) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	
	char str[5];
	
	scanf("%s", str);
	
	
	if(str[0]==str[1]&&str[0]==str[2]){
		printf("Yes");
	}else if(str[1]==str[2]&&str[1]==str[3]){
		printf("Yes");
	}else
	printf("No");	
	
	return 0;
}

Measured memory_bytes: 128
s = input().split()
m = 0
n = 0
if s[0] == '1':
  m += 300000
  n += 1
elif s[0] == '2':
    m += 200000
elif s[0] == '3':
    m += 100000
if s[1] == '1':
  m += 300000
  n += 1
elif s[1] == '2':
    m += 200000
elif s[1] == '3':
    m += 100000
if n == 2:
  m += 400000
print(m)

Measured memory_bytes: 3060
import System.Environment
import Data.Maybe
import Data.List
import Control.Exception

main :: IO ()
main = do
  isTest <- getEnv "TEST" `catch` (\(SomeException _) -> return "")
  if isTest == "1"
    then do
      testFile <- readFile "tests"
      putStrLn $ tests testFile
    else do
      input <- getContents
      putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s =
  show
    $ x
    + ( sum
      . fmap (\a -> (length . takeWhile (<=d) . fmap (\x -> x * a + 1)) [0 ..])
      )
        list
 where
  (line1:line2:line3) = lines s
  n                   = read line1 :: Int
  [d, x]              = fmap read (words line2) :: [Int]
  list                = fmap read line3 :: [Int]

tests :: String -> String
tests text = case testParse text of
  Right bodys -> unlines (fmap (\(i, body) -> test i body) (zip [1 ..] bodys))
  Left  msg   -> "Test file parse error:" ++ msg

test :: Int -> (String, String) -> String
test n (input, outputRight)
  | output == outputRight
  = header ++ "Passed"
  | otherwise
  = header
    ++ "Faild\n"
    ++ "Right:"
    ++ show outputRight
    ++ "\nOutput:"
    ++ show output
 where
  header = "test" ++ show n ++ ":"
  output = trim $ solve input

testParse :: String -> Either String [(String, String)]
testParse s = case lines s of
  (sp1:sp2:bodys) -> testBodysParse sp1 sp2 bodys
  _               -> Left "testParse"

testBodysParse
  :: String -> String -> [String] -> Either String [(String, String)]
testBodysParse sp1 sp2 = (traverse . testBodyParse) sp2 . (split sp1)

testBodyParse :: String -> [String] -> Either String (String, String)
testBodyParse sp body = case fmap (trim . unlines) (split sp body) of
  [input, output] -> Right (input, output)
  _               -> Left "testBodyParse"

split :: Eq a => a -> [a] -> [[a]]
split spratar = foldr f [[]]
 where
  f x (p:ps) | x == spratar = [] : p : ps
             | otherwise    = (x : p) : ps
  f _ _ = undefined

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 892
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define fst first
#define snd second
using ll = long long;
using I = pair<int, int>;

ll fizzbuzz(ll X) { return X / 3 + X / 5 - X / 15; }

ll f(ll X) {
  ll ans = 0;
  ll d = 1, p10 = 1;
  while (10 * p10 <= X) {
    ll c = p10 * 9;
    ll fb = fizzbuzz(p10 * 10 - 1) - fizzbuzz(p10 - 1);
    ans += (c - fb) * d;
    ++d;
    p10 *= 10;
  }
  ll c = X - p10 + 1;
  ll fb = fizzbuzz(X) - fizzbuzz(p10 - 1);
  ans += (c - fb) * d;
  ans += 4 * (X / 3) + 4 * (X / 5);
  return ans;
}

int main() {
  ll s;
  while (cin >> s) {
    ll fail = 0, pass = 1ll << 60;
    while (pass - fail > 1) {
      ll X = (fail + pass) / 2;
      if (f(X) >= s) {
        pass = X;
      } else {
        fail = X;
      }
    }
    if (pass > 1) {
      s -= f(pass - 1);
    }
    string ans = "";
    for (ll X = pass; ans.size() < s + 19; X++) {
      if (X % 15 == 0) {
        ans += "FizzBuzz";
      } else if (X % 3 == 0) {
        ans += "Fizz";
      } else if (X % 5 == 0) {
        ans += "Buzz";
      } else {
        ans += to_string(X);
      }
    }
    ans = ans.substr(s - 1, 20);
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
const int N=210;
char s[N][N];
int n,ans;
int col[N],b[N],f[N][N];
void bfs(int now){
	queue<int>q;
	memset(b,0,sizeof(b));
	f[now][now]=0; b[now]=1;
	q.push(now);
	while (!q.empty()) {
		int t=q.front(); q.pop();
		for (int j=1;j<=n;j++)
		 if (!b[j]&&(s[t][j]=='1')) {
		 	f[now][j]=f[now][t]+1;
		 	b[j]=1; q.push(j);
		 }
	}
	for (int i=1;i<=n;i++) ans=max(ans,f[now][i]);
}
bool dfs(int now){
	int p=1;
	for (int i=1;i<=n;i++)
	 if (s[now][i]=='1') {
	 	if (col[i]!=-1&&(col[i]==col[now])) { return 0;}
	 	if (col[i]==-1) {
	 		col[i]=col[now]^1;
	 		p&=dfs(i);
		 }
	 }
	 if (p) return 1; else return 0;
}
bool pan(){
	col[1]=1;
	return dfs(1);
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
	}
	for (int i=1;i<=n;i++) col[i]=-1;
	if (!pan()) {
		puts("-1"); return 0;
	}
	for (int i=1;i<=n;i++) bfs(i);
	printf("%d\n",ans+1);
}

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

using std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;

static long
gcm(long a, long b)
{
  long m = max(a, b);
  long n = min(a, b);
  for (;;)
  {
    long r = m % n;
    if (r == 0)
    {
      break;
    }
    m = n;
    n = r;
  }
  return n;
}

int
main()
{
  long A, B;
  cin >> A >> B;
  long g = gcm(A, B);
  int count = 0;
  for (long x = 2; x <= g / x; x++)
  {
    bool found = false;
    while (g % x == 0)
    {
      g /= x;
      found = true;
    }
    if (found)
    {
      count++;
    }
  }
  if (g != 1)
  {
    count++;
  }
  count++;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools

N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = [(p+1)/2 for p in P]
A = list(itertools.accumulate(Q))
A = [0] + A
mx = 0
for i in range(N-K+1):
    mx = max(mx, A[i+K]-A[i])
print(mx)

Measured memory_bytes: 80776
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  //cout<<fixed<<setprecision(10);
  ll n,ans=0;
  string s;
  cin>>s;
  if(s=="ABC")cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
}


Measured memory_bytes: 3588
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

int a[55], b[55];

int n;

bool bit(ll x, int p) {
	return x & (1ll << p);
}

bool check(ll m) {
	for (int i = 1; i <= n; ++i) {
		ll cur = (1ll << a[i]);

		for (int j = 50; j > 0; --j) {
			if (bit(m, j)) {
				for (int p = 0; p < j; ++p) {
					if (!bit(cur, p)) {
						for (int nx = p + j; nx <= 50; nx += j) {
							if (bit(cur, nx)) {
								cur |= (1ll << p);
								break;
							}
						}
					}
				}                
			}			
		}

		if (!bit(cur, b[i])) {
			return 0;
		}
	}	

	return 1;
}

void solve() {
	scanf("%d", &n);

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

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

	ll mask = (1ll << 51) - 2ll;

	if (!check(mask)) {
		printf("-1\n");
		return;
	}

	for (int i = 50; i > 0; --i) {
		mask -= (1ll << i);

		if (!check(mask)) {
			mask += (1ll << i);
		}
	}

	printf("%lld\n", mask);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>

using namespace std;

int main(void)
{
	int useP=0,useR=0;
	string s;
	int res = 0;

	cin >> s;

	res = 0;
	useR = 1;
	for (int i = 1 ; i < s.length(); i++)
	{
		//cout << res << endl;
		if (useP >= useR)
		{
			if (s[i] == 'p')
			{
				res = res - 1;
			}
			useR++;
		}
		else
		{
			if(s[i]=='g')
			{
				res += 1;
			}
			useP++;
		}

	}

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



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

using namespace std;
typedef long long ll;

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

int main(){
// ここに処理を記述
    int a;
    string s;

    cin >> a >> s;

    if(a>=3200) cout << s << "\n";
    else cout << "red" << "\n";

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int> a;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(a.count(x))
			a.erase(x);
		else
			a[x]=0;
	}
	cout<<a.size()<<endl;
	return 0;
}

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

typedef long long ll;

template <class T>
void printArray(vector<T> arr) {
	for (T a: arr) cout << a << " ";
	cout << '\n';
}

void printVerdict(bool verdict) {
	cout << (verdict ? "YES": "NO") << '\n';
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<string, int> count;
	
	count["AC"] = 0;
	count["WA"] = 0;
	count["TLE"] = 0;
	count["RE"] = 0;
	
	for (int i = 0; i<n; i++) {
		string temp; cin >> temp;
		count[temp]++;
	}
	cout << "AC x " << count["AC"] << '\n';
	cout << "WA x " << count["WA"] << '\n';
	cout << "TLE x " << count["TLE"] << '\n';
	cout << "RE x " << count["RE"] << '\n'; 
}



Measured memory_bytes: 3636
<>=~$";@a=glob`dd`;$a[$_-1]%2&&++$a[$%=$_%$'?$_:$_-1+$']*$%&&push@_,"@{[map{$_/$'+1|0,$_%$'+1}$_-1,$%]}
"for 1..$`*$'-1;print@_.$/,@_

Measured memory_bytes: 64328
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,m;cin>>n>>m;
    
    vp x;
    rep(i,m){
        ll a,b;cin>>a>>b;
        x.emplace_back(b,a);
    }

    sort(all(x));
    ll ans=0;
    ll pos=-1;
    for(auto &p:x){
        if(pos>p.second)continue;
        ++ans;
        pos=p.first;
    }
    cout<<ans<<endl;
}

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

int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    if(n%2==1) cout<<0<<endl;
    else{
    n/=2;
    while(n>=5){
        n/=5;
        ans+=n;
    }
    cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int n, k;
int d[114], memo[114];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int ans = 0;
	cin >> n >> k;
	rep(i, k) {
		cin >> d[i];
		rep(j, d[i]) {
			int a;
			cin >> a;
			memo[a]++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (memo[i] == 0)ans++;
	}
	cout << ans << endl;
	ggr
}


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

int dp[100005][3] = {0};
int data[100005][3] = {0};
int n;

int solve();

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 3; ++j) cin >> data[i][j];
  cout << solve() << endl;
  return 0;
}

int solve() {
  for(int i = 0; i < 3; ++i) dp[0][i] = data[0][i];
  for(int i = 1; i < n; ++i)
    for(int j = 0; j < 3; ++j)
      for(int k = 0; k < 3; ++k)
        if(j != k)
          dp[i][j] =
              max(dp[i][j], data[i][j] + dp[i - 1][k]);
  return max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]);
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
int N, k;
string ans;
int main() {
  cin >> N;
  while (N != 0) {
    bool multi = false;
    int exist = 0;
    for (int i = 0; i < N; i++) {
      cin >> k;
      if (k >= 2) {
        multi = true;
      }
      if (k > 0) {
        exist++;
      }
    }
    if (multi) {
      ans += to_string(exist + 1);
    } else {
      ans += "NA";
    }
    ans += "\n";
    cin >> N;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3256