akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const ll mod=1e9+7;
const ll segN=(1LL<<22);

ll calc(ll a,ll b){
  return (a+b)%mod;
}

ll mul(ll x,ll y){return (x*y)%mod;}
ll pow(ll x,ll y){
  ll v=1;
  for(;y;x=mul(x,x),y>>=1)
    if(y&1)v=mul(v,x);
  return v;
}
ll divi(ll x,ll y){return mul(x,pow(y,mod-2));}

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

struct data{
  ll value;
  data* ch[2];
 
  void init(){
    value=0;
    ch[0]=(data*)malloc(sizeof(data));
    ch[1]=(data*)malloc(sizeof(data));
    ch[0]->ch[0]=NULL;
    ch[1]->ch[0]=NULL;
  }
  
  void add(ll i,ll x,ll l,ll r){
    ll m=(l+r)/2;
    if(ch[0]==NULL)init();
    if(i<l || r<=i)return;
    value=calc(value,x);
    if(r-l==1)return;
    ch[0]->add(i,x,l,m);
    ch[1]->add(i,x,m,r);
  }
   
  void add(ll i,ll x){
    add(i,x,0,segN);
  }
   
  ll sum(ll a,ll b,ll l,ll r){
    ll m=(l+r)/2;
    if(ch[0]==NULL)init();
    if(b<=l || r<=a)return 0;
    if(a<=l && r<=b)return value;
    ll res=0;
    res=calc(res,ch[0]->sum(a,b,l,m));
    res=calc(res,ch[1]->sum(a,b,m,r));
    return res;
  }
 
  ll sum(ll a,ll b){
    return sum(a,b,0,segN);
  }
};



struct data2{
  ll value;
  data2* ch[2];
 
  void init(){
    value=1;
    ch[0]=(data2*)malloc(sizeof(data));
    ch[1]=(data2*)malloc(sizeof(data));
    ch[0]->ch[0]=NULL;
    ch[1]->ch[0]=NULL;
  }
  
  void set(ll i,ll x,ll l,ll r){
    ll m=(l+r)/2;
    if(ch[0]==NULL)init();
    if(i<l || r<=i)return;
    value=lcm(value,x);
    if(r-l==1)return;
    ch[0]->set(i,x,l,m);
    ch[1]->set(i,x,m,r);
  }
   
  void set(ll i,ll x){
    set(i,x,0,segN);
  }
   
  ll getLcm(ll a,ll b,ll l,ll r){
    ll m=(l+r)/2;
    if(ch[0]==NULL)init();
    if(b<=l || r<=a)return 1;
    if(a<=l && r<=b)return value;
    ll res=1;
    res=lcm(res,ch[0]->getLcm(a,b,l,m));
    res=lcm(res,ch[1]->getLcm(a,b,m,r));
    return res;
  }
 
  ll getLcm(ll a,ll b){
    return getLcm(a,b,0,segN);
  }
};
 
#define MAX 100005
ll N,Q;
ll t[MAX],u[MAX],v[MAX];
bool visited[MAX];
data T;
data2 U;

bool isP(ll x){
  if(x<2)return false;
  for(ll i=2;i*i<=x;i++)
    if(x%i==0)return false;
  return true;
}

int main(){
  /*  
  ll nn=1;
  for(int i=2;i<=40;i++)
    if(isP(i))nn*=i;  
  cout<<nn*16LL*9LL*5LL<<endl;
  */
  
  T.init();
  U.init();
  
  cin>>N>>Q;
  for(int i=1;i<=N;i++){
    cin>>t[i];
    visited[i]=false;
  }
  
  for(int i=1;i<=N;i++){
    if(visited[i])continue;
    ll sum=0,pos=i;
    vector<ll> vec;
    while(!visited[pos]){
      visited[pos]=true;
      sum=calc(sum,pos);
      vec.push_back(pos);
      pos=t[pos];
    }

    for(int j=0;j<(int)vec.size();j++){
      u[vec[j]]=sum;
      v[vec[j]]=vec.size();
    }

  }
  
  ll g=1;
  for(int i=1;i<=N;i++){
    g=lcm(g,v[i]);
  }
  //  cout<<g<<endl;
  
  for(int i=1;i<=N;i++){
    ll A=u[i];
    A=mul(A,(g/v[i])%mod);
    T.add(i,A);
    U.set(i,v[i]);
  }

  ll l,r;
  for(int i=0;i<Q;i++){
    cin>>l>>r;
    ll A=T.sum(l,r+1);
    ll B=U.getLcm(l,r+1);
    
    cout<<divi(A,(g/B)%mod)<<endl;
  }
  return 0;
}

Measured memory_bytes: 28672
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int a = stoi(s.substr(0, 2)), b = stoi(s.substr(2, 2));
  auto mm = [](int n) {
    if (n > 0 && n <= 12)
      return true;
    return false;
  };
  if (!mm(a) && mm(b))
    cout << "YYMM" << endl;
  else if (mm(a) && !mm(b))
    cout << "MMYY"<< endl;
  else if (mm(a) && mm(b))
    cout << "AMBIGUOUS" << endl;
  else
    cout << "NA" << endl;
  return 0;
}

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

using namespace std;

int arr[1000001];

vector<int> vis(1000001,0);

int main(){
   int n;
   cin>>n;
   int mx=0;
   for(int i=0;i<n;i++){
   	cin>>arr[i];
   	mx=max(mx,arr[i]);
   }
   bool flag=false;
   for(int i=0;i<n;i++){
   	  int m=arr[i];
   	  for(int j=1;j<=sqrt(m);j++){
   	  	if(m%j==0){
   	  		vis[j]++;
   	  		if(vis[i]>1&&i!=1){
   	  			flag=true;
   	  			break;
   	  		}
    
   	  		if(j!=m/j){
   	  			vis[m/j]++;
              if(vis[m/j]>1&&m/j!=1){
              flag=true;
              break;}
              
   	  		}
   	  	}
        
   	  }
     if(flag==true){
     break;}
   	  
   }
   
   if(flag==false){
   	cout<<"pairwise coprime"<<endl;
   	return 0;
   }
   int x=__gcd(arr[0],arr[1]);
   for(int i=1;i<n;i++){
   	  x=__gcd(x,arr[i]);
   }
   if(x==1){
   	cout<<"setwise coprime"<<endl;
   }
   else{
   	cout<<"not coprime"<<endl;
   	
   }
}


Measured memory_bytes: 11092
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


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

	cin >> N;
	while(N){
	    N = 1000 - N;
	if (N >= 500)N -= 400;
	int ans = N / 100;
	N %= 100;
	if (N >= 50)N -= 40;
	ans += N / 10;
	N %= 10;
	if (N >= 5)N -= 4;
	ans += N;
	cout << ans << endl;
	cin>>N;
	}
	return 0;
}



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

int k; 
int main() { 
  scanf("%d", &k);
  int odds = k / 2; 
  int evens = k / 2; 
  if (k % 2) {
    odds++; 
  } 
  cout << odds * evens;
  return 0;
} 

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#ifdef LOCAL
#define cerr cout
#else
#endif

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 1005;
const int M = 200005;
bool not_necessary[N][N];
vector<int> con[N];
int a[M], b[M];
int vis[N];
int fe[N];

struct graph {
  int n;
  vector<vector<int>> adj;
  graph(int n) : n(n), adj(n) { }
  void add_edge(int src, int dst) {
    adj[src].push_back(dst);
  }

  vector<vector<int>> strongly_connected_components() {
    vector<vector<int>> scc;
    vector<int> S, B, I(n);
    function<void(int)> dfs = [&](int u) {
      B.push_back(I[u] = S.size());
      S.push_back(u);
      for (int v: adj[u]) {
        if (!I[v]) dfs(v);
        else while (I[v] < B.back()) B.pop_back();
      }
      if (I[u] == B.back()) {
        scc.push_back({});
        B.pop_back();
        for (; I[u] < S.size(); S.pop_back()) {
          scc.back().push_back(S.back());
          I[S.back()] = n + scc.size();
        }
      }
    };
    for (int u = 0; u < n; ++u)
      if (!I[u]) dfs(u);
    return scc; // I[u] - n is the index of u
  }
};


int main(){
	int n, m; sd(n); sd(m);
	graph g(n + 1);
	for(int i = 1; i <= m; i++){
		sd(a[i]);
		sd(b[i]);
		con[a[i]].push_back(b[i]);
		g.add_edge(a[i], b[i]);
	}
	vector<vector<int>> comp = g.strongly_connected_components();
	vector<int> where(n + 1);
	for(int i = 0; i < comp.size(); i++)
		for(auto it : comp[i])
			where[it] = i;
	queue<pii> q;
	for(int i = 1; i <= n; i++){
		memset(vis, 0, sizeof vis);
		for(int v : con[i]){
			q.push({v, v});
			vis[v] = 1;
			fe[v] = v;
		}
		while(!q.empty()){
			auto it = q.front();
			q.pop();
			int u = it.F, firstEdge = it.S;
			for(int v : con[u]){
				if(v == i || vis[v] >= 2) continue;
				if(vis[v] == 1 && firstEdge == fe[v]) continue;
				q.push({v, firstEdge});
				if(vis[v] == 0)
					fe[v] = firstEdge;
				vis[v]++;
			}
		}
		for(int v : con[i]) if(vis[v] == 2){
			not_necessary[i][v] = 1;
		}
	}
	for(int i = 1; i <= m; i++){
		printf( (not_necessary[a[i]][b[i]] ^ (where[a[i]] != where[b[i]] )) ? "same\n" : "diff\n");
	}
}

Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        scanner.close();

        int odd = (N + 1) / 2;
        double ans = (double) odd / N;

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
#define MAX 250005
using namespace std;

long long factorial[MAX] = {0}, finverse[MAX] = {0},
          inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for(int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if(n == k && n == 0) return 1;
  if(n < 0 || k < 0 || n < k) return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] %
         N;
}

long long rc[2], a[2], b[2], ch[2], data[2][3] = {0},
                                    cost = 0, ans = 0;
long long solve();
long long calc(int x, int y);
long long setd(int x);

int main() {
  smodfact();
  cin >> rc[0] >> rc[1] >> a[0] >> a[1] >> b[0] >> b[1];
  ans = solve();
  cout << cost << " " << ans << endl;
  return 0;
}

long long solve() {
  long long xy[2], ans = 0, nowx, nowy;
  for(int i = 0; i < 2; ++i) xy[i] = setd(i);
  cost = xy[0] + xy[1];
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j) {
      nowx = data[0][i];
      nowy = data[1][j];
      if(xy[0] == nowx && xy[1] == nowy) {
        ans += calc(i, j);
        ans %= N;
      }
    }
  return ans;
}

long long setd(int x) {
  long long minn;
  data[x][0] = max(a[x] - b[x], b[x] - a[x]);
  minn = data[x][0];
  data[x][1] = b[x] + 1;
  minn = min(minn, data[x][1]);
  data[x][2] = rc[x] - b[x];
  minn = min(minn, data[x][2]);
  return minn;
}
long long calc(int x, int y) {
  return factorial[data[0][x] + data[1][y]] *
         finverse[data[0][x]] % N * finverse[data[1][y]] %
         N;
}


Measured memory_bytes: 8964
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

bool used[51][51];
char field[51][51];

using namespace std;

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

int h,w;
bool wok,bok;
int bfs(int x,int y){
	
	queue<pair<int,int> > *prv=new queue<pair<int,int> >();
	queue<pair<int,int> > *nxt=new queue<pair<int,int> >();
	
	bool white=false;
	bool black=false;

	int cnt=0;
	prv->push(make_pair(y,x));
	while(prv->size()){
		while(prv->size()){
			pair<int,int> cp = prv->front();prv->pop();
			if(used[cp.first][cp.second]){
				continue;
			}
			used[cp.first][cp.second]=true;
			cnt++;
			for(int i = 0; i < 4; i++){
				pair<int,int> np=cp;
				np.first+=dy[i];
				np.second+=dx[i];
				if(np.first >= 0 && np.second >= 0 && np.first < h && np.second < w){
					if(field[np.first][np.second]=='W'){
						white=true;
						continue;
					}
					else if(field[np.first][np.second]=='B'){
						black=true;
						continue;
					}

					if(!used[np.first][np.second]){
						nxt->push(np);
					}
				}
			}
		}
		swap(prv,nxt);
	}
	delete prv,nxt;

	if(white && black)
		return 0;
	else if(white){
		wok=true;
		return cnt;
	}
	else if(black){
		bok=true;
		return cnt;
	}
	else
		return 0;
}



int main(){

	while(cin>>w>>h&&!(w==0&&h==0)){
		for(int i = 0; i < h; i++)
			fill(used[i],used[i]+w,false);

		int wcnt=0;
		int bcnt=0;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(i==0&&j==4){
//					cout<<endl;
				}
				wok=false;
				bok=false;
				if(used[i][j]||field[i][j]!='.')
					continue;
				int ccc = bfs(j,i);
				if(wok)
					wcnt+=ccc;
				else if(bok)
					bcnt+=ccc;
			}
		}
		cout << bcnt << " " << wcnt << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int H[100005], sum[100005];

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

	if (n == 1) cout << 0;
	else {

		int j = 0;
		for (int i = 0; i < n - 1; i++) {
			if (H[i] >= H[i + 1]) sum[j]++;
			else j++;
		}

		int max = 0;
		for (int i = 0; i <= j; i++) {
			if (sum[i] > max) max = sum[i];
		}

		cout << max;
	}

	return 0;
}


Measured memory_bytes: 1024
N, Q = map(int, input().split())
S = input()
acList = [0 for n in range(N+1)]
for i in range(N):
    if("AC" == S[i:i+2]):
        acList[i+1] += acList[i] + 1
    else:
        acList[i+1] += acList[i]
for q in range(Q):
    left, right = map(int, input().split())
    print (acList[right-1] - acList[left-1])

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
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();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#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(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int a,b;
    int c;
    cin >> a >> b;
    a--;b--;
    if (b%a== 0) c= b/a;
    else c = b/a + 1;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
const int N = 10101010;
int main() { // cは後回しにしろ
	// 例えばさっきの開放では
	// n=5,m=5,k=100
	// a={96,1,1,1,1}
	// b={1,50,50,50,50}でだめ
	int n, m; ll k;
	cin >> n >> m >> k;
	VL suma(n + 1, 0), sumb(m + 1, 0);
	rep(i, n) {
		int a;
		cin >> a;
		suma[i + 1] = suma[i] + a;
	}
	rep(i, m) {
		int b;
		cin >> b;
		sumb[i + 1] = sumb[i] + b;
	}
	// aを上から何冊読むか？を決め打つべき
	// 二分探索を用いてnlogm
	ll ans = 0;
	rep(i, n + 1) {
		ll x = i;
		if (suma[i] > k) break;
		ll y = upper_bound(all(sumb), k - suma[i]) - sumb.begin() - 1;
		chmax(ans, x + y);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6332
import java.util.*;

public class Main{
	static final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		double x1,x2,x3,y1,y2,y3;
		int n = sc.nextInt();
		while( n-- > 0 ){
			x1 = sc.nextDouble(); y1 = sc.nextDouble();
			x2 = sc.nextDouble(); y2 = sc.nextDouble();
			x3 = sc.nextDouble(); y3 = sc.nextDouble();
			double[] ans = solve( 2*(x1-x2), 2*(y1-y2), x1*x1+y1*y1-(x2*x2+y2*y2), 2*(x1-x3), 2*(y1-y3), x1*x1+y1*y1-(x3*x3+y3*y3));
			System.out.printf("%.3f %.3f %.3f\n", ans[0], ans[1], Math.sqrt( Math.pow(ans[0]-x1, 2) + Math.pow(ans[1]-y1, 2) ) );
		}
	}
	static double[] solve(double a, double b, double c, double d, double e, double f){
		double[] ans = new double[2];
		ans[0] = (c*e - b*f) / (a*e - b*d) + 0.0;
		ans[1] = (a*f - c*d) / (a*e - b*d) + 0.0;
		return ans;
	}
}

Measured memory_bytes: 20780
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] ci = new int[n];
        int[][] aij = new int[n][m];

        for (int i=0; i<n; i++) {
            ci[i] = sc.nextInt();
            for (int j=0; j<m; j++) {
                aij[i][j] = sc.nextInt();
            }
        }

        if (canSuccess(x, aij)) {
            System.out.println(minCost(x, ci, aij));
        } else {
            System.out.println("-1");
        }
    }
    private static int minCost(int x, int[] ci, int[][] aij) {
        boolean[] t = new boolean[ci.length];
        for (int i=0; i<t.length; i++) {
            t[i] = true;
        }
        int minCost = cost(t, ci);

        return minCostR(minCost, x, t, ci, aij);
    }
    private static int minCostR(int nowMin, int x, boolean[] t, int[] ci, int[][] aij) {
        List<boolean[]> recTlist = new ArrayList<>();
        int start = 0;
        for (int i=t.length-1; i>=0; i--) {
            if (!t[i]) {
                start = i;
                break;
            }
        }
        for (int i=start; i<t.length; i++) {
            if (t[i]) {
                boolean[] newT = copyT(t);
                newT[i] = false;
                if (canSuccess(x, newT, aij)) {
                    int cost = cost(newT, ci);
                    if (nowMin > cost) {
                        nowMin = cost;
                    }
                    recTlist.add(newT);
                }
            }
        }
        for (boolean[] recT : recTlist) {
            nowMin = minCostR(nowMin, x, recT, ci, aij);
        }
        return nowMin;
    }
    private static boolean[] copyT(boolean[] t) {
        boolean[] ret = new boolean[t.length];
        for (int i=0; i<ret.length; i++) {
            ret[i] = t[i];
        }
        return ret;
    }
    private static int cost(boolean[] t, int[] ci) {
        int sum = 0;
        for (int i=0; i<t.length; i++) {
            if (t[i]) {
                sum += ci[i];
            }
        }
        return sum;
    }
    private static boolean canSuccess(int x, boolean[] t, int[][] aij) {
        int[] sum = new int[aij[0].length];
        for (int i=0; i<aij.length; i++) {
            if (t[i]) {
                for (int j = 0; j < aij[i].length; j++) {
                    sum[j] += aij[i][j];
                }
            }
        }
        return Arrays.stream(sum).allMatch(s -> s >= x);
    }
    private static boolean canSuccess(int x, int[][] aij) {
        boolean[] t = new boolean[aij.length];
        for (int i=0; i<t.length; i++) {
            t[i] = true;
        }
        return canSuccess(x, t, aij);
    }
}

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

int main() {
  typedef long long ll;
  char b;
  cin >> b;
  
  if (b == 'A') {
    cout << 'T' << endl;
  }
  else if (b == 'T') {
    cout << 'A' << endl;
  }
  else if (b == 'C') {
    cout << 'G' << endl;
  }
  else {
    cout << 'C' << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

struct UnionFind
{
    vector<ll> data;

    UnionFind(ll sz)
    {
        data.assign(sz, -1);
    }

    bool connected(ll x, ll y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return true;
        else
            return false;
    }

    bool unite(ll x, ll y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    ll find(ll k)
    {
        if (data[k] < 0)
            return k;
        return (data[k] = find(data[k]));
    }

    ll size(ll k)
    {
        return (-data[find(k)]);
    }
};

ll a[100010], b[100010];
ll c[100010];

int main()
{
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    c[m] = n * (n - 1) / 2;
    for (int i = m - 1; i > 0; i--)
    {
        if (uf.connected(a[i], b[i]))
        {
            c[i] = c[i + 1];
        }
        else
        {
            c[i] = c[i + 1] - uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }
    for (int i = 1; i <= m; i++)
    {
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 4480
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[-1]+a[i])
for i in range(m):
    bsum.append(bsum[-1]+b[i])
ans=0
for i in range(n+1):
    if asum[i]>k:
        break
    while asum[i]+bsum[m]>k and m>0:
        m-=1
    ans=max(ans,i+m)
print(ans)

Measured memory_bytes: 47344
#include <cstdio>
#include <algorithm>

using namespace std;

int M,N;

const int MAXN=7368799;

bool arr[MAXN];

int main(){
    while (scanf("%d%d",&M,&N)&&M!=0&&N!=0){
        fill(arr+M,arr+MAXN,false);
        int k=M;
        for(int i=0;i<N;i++){
            while (arr[k]) k++;
            for(int j=k;j<MAXN;j+=k) arr[j]=true;
        }

        int y=M;
        while (arr[y]) y++;

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

    return 0;
}


Measured memory_bytes: 9796
#include<stdio.h>
#include<math.h>
int main()
{
	long long N,x,y,l,a=1E13;
	scanf("%lld",&N);
	for(x=1;x<=sqrt(N);x++)
	{
		if(N%x==0)
		{
			y=N/x;
			l=x-1+y-1;
		}
		if(a>=l)
			a=l;
		else
			continue;
	}
	printf("%lld\n",a);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

const int mxn = 3005;
ll dp[mxn][mxn];

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int l = n - 1; l >= 0; l--) {
		for (int r = l; r < n; r++) {
			if (l == r) {
				dp[l][r] = a[l];
			} else {
				dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
			}
		}
	}

	cout << dp[0][n - 1] << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 70016
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

typedef long long ll;

#define min(a, b) (((a) < (b))? (a):(b))
#define max(a, b) (((a) > (b))? (a):(b))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define rep(i, n) REP(i, 0, (n))
#define square(a) (a)*(a)
#define pb push_back

int n,W;
int weight[110],value[110];

int dp[110][10010];

int main(){
    cin >> n >> W;
    rep(i,n) cin >> value[i] >> weight[i];
    
    rep(w,W) dp[0][w] = 0;
    
    rep(i,n){
        for (int w = 0; w <= W; ++w){
            if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i] , dp[i][w]);
            else dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[n][W] << endl;
}



Measured memory_bytes: 7024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define ll unsigned long long
using namespace std;

int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)
		cout << (b - a) / 2 << endl;
	else
	{
		ll x = n - b;
		ll y = a - 1;
		ll z = min(x, y);
		cout << z + 1 + (b - a) / 2<< endl;
	}

	return 0;
}

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

using namespace std;
typedef pair<int,int> P;

bool cmp(const P& a,const P& b)
{
  if(a.first == b.first)
    return a.second < b.second;
  return a.first > b.first;
}

int main()
{
  int n;
  vector<P> vec;
  cin >> n;
  for(int i=0;i<n;i++)
    {
      int a,v;
      cin >> a >> v;
      vec.push_back(P(v,a));
    }
  sort(vec.begin(),vec.end(),cmp);
  cout << vec[0].second << " " << vec[0].first << endl;
  return 0;
}

Measured memory_bytes: 1204
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	int A, B; cin >> A >> B;
	if (A <= 8 && B <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define the_num 1000000007
#define ano_num 998244353
#define forn(n) for(int i=0;i<n;i++)
#define For(i,start_i,n) for(int i=start_i;i<n;i++)
#define test int t;cin >> t;while(t--)
#define all(v) v.begin(),v.end()
#define in_arr(arr,n) int arr[n];forn(n) cin >> arr[i];
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define take(data_type,n) data_type n;cin >> n;
#define swap(a,b) a = a+b;b = a-b;a = a-b;
using namespace std;

int main(){
    fast
    int a,b;
    cin >> a >> b;
    cout << a*b << '\n';

}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys
import collections
import math

sys.setrecursionlimit(10 ** 7)

# 1 ✕ N
A, B, C, D = list(map(int, input().rstrip().split()))
ar = (360 / 12) * C + D * 0.5
br = (360 / 60) * D

print(math.sqrt(A * A + B * B - (2 * A * B * math.cos(math.radians(abs(ar - br))))))


Measured memory_bytes: 9792
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

if 1 in a:
    print(1)
    exit()

while len(a)!=1:
    m = min(a)
    ind = a.index(m)
    for i in range(len(a)):
        if i==ind:
            pass
        else:
            a[i] = a[i] % m
    a = list(set(a))
    if 0 in a:
        a.remove(0)
    elif 1 in a:
        print(1)
        exit()
    # print(a)

print(a[0])
exit()

Measured memory_bytes: 90888
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define f first
#define s second

typedef pair<int, int> P;
typedef pair<P, P> P2;

int convert(int a, int b, int c, int d){
  return a*10 + b*50 + c*100 + d*500;
}

int main(){
  int price, a, b, c, d;
  int cs = 0;
  while(cin >> price){
    if(price == 0) break;
    if(cs++ != 0) cout << endl;
    cin >> a >> b >> c >> d;
    vector<pair<int, P2> > data;

    int cnt[4];
    for(int i = 0 ; i <= a ; i++){
      for(int j = 0 ; j <= b ; j++){
	for(int k = 0 ; k <= c ; k++){
	  for(int l = 0 ; l <= d ; l++){
	    int v = convert(i, j, k, l);
	    if(price > v) continue;
	    v -= price; //テ」ツ?甘ゥツ?」テ」ツつ?
	    
	    cnt[3] = v / 500; v %= 500;
	    cnt[2] = v / 100; v %= 100;
	    cnt[1] = v / 50; v %= 50;
	    cnt[0] = v / 10; v %= 10;

	    if((i > 0 && cnt[0] > 0) || (j > 0 && cnt[1] > 0) ||
	       (k > 0 && cnt[2] > 0) || (l > 0 && cnt[3] > 0)) continue;
	  
	    int sum = (cnt[0]+cnt[1]+cnt[2]+cnt[3]) - (i+j+k+l);
	    P2 tmp;
	    tmp.f.f = -i, tmp.f.s = -j, tmp.s.f = -k, tmp.s.s = -l;
	    data.push_back(make_pair(sum, tmp));
	  }
	}
      }
    }
    sort(data.begin(), data.end());
    if(-data[0].s.f.f > 0) cout << 10 << ' ' << -data[0].s.f.f << endl;
    if(-data[0].s.f.s > 0) cout << 50 << ' ' << -data[0].s.f.s << endl;
    if(-data[0].s.s.f > 0) cout << 100 << ' ' << -data[0].s.s.f << endl;
    if(-data[0].s.s.s > 0) cout << 500 << ' ' << -data[0].s.s.s << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
N,Y=map(int,input().split())
x=Y//1000-N
p=0
for i in range(0,x//9+1,1):
    if (x-9*i)%4==0:
        a=i
        b=(x-9*i)//4
        c=N-a-b
        if c>=0:
            print(str(a)+' '+str(b)+' '+str(c))
            break
        else:
            p+=1
    else:
        p+=1
if p==x//9+1:
    print('-1 -1 -1')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
        swap(a,b);
    if(a==1&&b==2)
        cout<<"3"<<endl;
    else if(a==1&&b==3)
        cout<<"2"<<endl;
    else
        cout<<"1"<<endl;
    return 0;
}


Measured memory_bytes: 256
solve :: Int -> Int -> Int -> Int -> Int
solve a b c k = (a + b + c) + max * (2^k - 1)
  where max = maximum [a, b, c]

main :: IO ()
main = do
  [a, b, c] <- map read . words <$> getLine
  k <- readLn
  print $ solve a b c k

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

int main(){
    int x;cin>>x;
    if(x == 7 || x == 5 || x == 3)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){
  long long N;
  cin>>N;
  long long A[N];
  long long sum=0;
  map<long long,long long>mp;
  for(long long i=0;i<N;i++){
    cin>>A[i];
    sum+=A[i];
    mp[A[i]]++;
  }
  
  long long Q;
  cin>>Q;
  
  long long B[Q];
  long long C[Q];

  for(long long i=0;i<Q;i++){
    cin>>B[i]>>C[i];
    sum+=(C[i]-B[i])*mp[B[i]];
    cout<<setprecision(18)<<sum<<endl;
    
    mp[C[i]]+=mp[B[i]];
    mp[B[i]]=0;
    
    
  }
  return 0;
}


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

int main()
{
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1) cout << 1 << endl;
    else if(h % 2 == 0) cout << h / 2 * w << endl;
    else if(w % 2 == 0) cout << w / 2 * h << endl;
    else cout << (h - 1) / 2 * w + w / 2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
c = ns()
aw = c.count('W')
ans = min(n-aw,aw)
w = 0

for i in range(n):
    if c[i] == 'W': w+=1
    rw = aw-w
    rr = n-i-1-rw
    ans = min(ans, max(w,rr))

print(ans)

Measured memory_bytes: 9496
require 'set'

N, M, P = gets.split.map(&:to_i)
abc_list = M.times.map do
  a, b, c = gets.split.map(&:to_i)
  [a - 1, b - 1, -(c - P)]
end
graph = Array.new(N) { [] }
abc_list.each do |(a, b, c)|
  graph[a].push([b, c])
end
reverse_graph = Array.new(N) { [] }
abc_list.each do |(a, b, c)|
  reverse_graph[b].push([a, c])
end

INF = 1 << 60

def reachable(graph, s)
  visit = Set.new
  visit.add(s)
  queue = [s]
  while !queue.empty?
    u = queue.shift
    graph[u].each do |(v, _)|
      next if visit.include?(v)
      visit.add(v)
      queue.push(v)
    end
  end
  visit
end

def bellman_ford(edge_list, s, max_count)
  d = Array.new(N, INF)
  d[s] = 0
  c = 0
  loop do
    is_update = false
    edge_list.each do |(u, v, c)|
      if d[u] != INF && d[u] + c < d[v]
        d[v] = d[u] + c
        is_update = true
      end
    end
    return d if !is_update
    c += 1
    return nil if c == max_count
  end
end

reachable_from_0 = reachable(graph, 0)
reachable_to_n = reachable(reverse_graph, N - 1)
v_set = Set.new
N.times do |v|
  v_set.add(v) if reachable_from_0.include?(v) && reachable_to_n.include?(v)
end
edge_list = abc_list.select do |(a, b, _)|
  v_set.include?(a) && v_set.include?(b)
end
ans = bellman_ford(edge_list, 0, v_set.size)
puts(ans == nil ? '-1' : [-(ans[N - 1]), 0].max)


Measured memory_bytes: 5116
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    if(n%2!=0){
        cout<<"0";
        return 0;
    }
    ll l1=0;
    for(ll i=1;i<=26;i++){
        ll g=pow(5,i)*2;
        if(g > n) break;
        ll r=n/g;
        if(i*(r- r/5) >0)
        l1+=i*(r- r/5);
    }
    cout<<l1;
}

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

int main(){
    ios_base::sync_with_stdio(0);
    int N;
    cin >> N;
    int K;
    cin >> K;
    V.resize(N);
    for (int i = 0; i < N; i++){
        cin >> V[i];
    }
    vector <long long> DP(N, 99999999999);
    DP[0] = 0;
    
    for (int i = 1; i < N; i++){
        // cerr << i << "\n";
        for (int poz = i-1; poz >= max(i - K, 0) ; poz--){
            DP[i] = min(DP[i], DP[poz] + abs(V[i] - V[poz]));
        }
        // cerr << DP[i] << "===\n";
    }
    cout << DP[N-1];
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> kind(8, 0);
    int cnt = 0;
    rep(i, N) cin >> a[i];
    rep(i, N) {
        if (a[i] >= 3200) {
            cnt++;
        }
        else {
            kind[a[i] / 400]++;
        }
    }

    int a_min = 0, a_max = 0;
    rep(i, 8) {
        if (kind[i] > 0) a_min++;
    }

    cout << max(a_min, 1) << " " << a_min + cnt << endl;
    return 0;
}

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

constexpr int MAX = 110;
constexpr int INF = 1e9;

int N;
int G[MAX][MAX];
bool seen[MAX];
int d[MAX];

int main(){
  for( int i = 0; i < MAX; i++ ){
    for( int j = 0; j < MAX; j++ ){
      G[i][j] = INF;
    }
  }
  
  cin >> N;
  for( int i = 0; i < N; i++ ){
    int u, k; cin >> u >> k;
    for( int j = 0; j < k; j++ ){
      int v, c; cin >> v >> c;
      G[u][v] = c;
    }
  }

  for( int i = 0; i < MAX; i++ ){
    d[i] = INF;
  }
  d[0] = 0;

  while( 1 ){
    int mincost = INF;
    int u;
    for( int i = 0; i < N; i++ ){
      if( d[i] < mincost && !seen[i] ){
	mincost = d[i];
	u = i;
      }
    }

    if( mincost == INF ) break;
    seen[u] = true;
    
    for( int i = 0; i < N; i++ ){
      if( G[u][i] != INF && !seen[i] ){
	if( G[u][i] + d[u] < d[i] ){
	  d[i] = G[u][i] + d[u];
	}
      }
    }
  }

  for( int i = 0; i < N; i++ ){
    cout << i << " " << d[i] << endl;
  }

}



Measured memory_bytes: 3148
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<array>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<list>
#include<numeric>
#include<deque>
#include<chrono>
using namespace std;

int main(){

    int a, b;
    cin >> a >> b;

    int max=-200;

    if(max < a + b)
        max = a + b;
    if(max < a - b)
        max = a - b;
    if(max < a * b)
        max = a * b;

    cout << max << endl;



    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vi b(n - 1);
	rep(i, n - 1) cin >> b[i];

	int ans = b.front() + b.back();
	rep(i, n - 2) {
		ans += min(b[i], b[i + 1]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 3636
N,A,B=map(int,input().split())
S=list(str(input()))
C=A+B

#予選通過リスト
OK=0
b_OK=0

for i in range(N):
  if S[i]=='a':
    if OK < C:
      print('Yes')
      OK+=1
    else:print('No')
  elif S[i]=='b':
    if OK < C and b_OK < B:
      print('Yes')
      OK+=1
      b_OK+=1
    else:print('No')
  else:print('No')

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

signed main() {
	int n;
	cin >> n;
	
	vector<int> a(n);
	vector<vector<pair<int, int>>> vp(2, vector<pair<int, int>> (100010));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		vp[i % 2][a[i]].first++;
	}
	
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < vp[i].size(); j++) {
			vp[i][j].second = j;
		}
		sort(vp[i].rbegin(), vp[i].rend());
	}
	
	int ans = 1e6;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (vp[0][i].second == vp[1][j].second) continue;
			int t = 0;
			for (int k = 0; k < n; k++) {
				t += (a[k] != vp[k % 2][k % 2 ? i : j].second);
			}
			
			ans = min(ans, t);
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 5760
N, K = map(int,input().split())
H=[]
for i in range (N):
    h=int(input())
    H.append(h)

H = sorted(H)
ans = H[K-1] - H[0]
for i in range (N-K+1):
    ans = min (ans, H[i+K-1]-H[i])

print(ans)

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

int N, Ma, Mb;
int a[41], b[41], c[41];

struct Data {
  int now, type_a, type_b, cost;
  bool operator < ( const Data &d ) const {
    if( cost != d.cost ) return cost > d.cost;
    if( now  != d.now ) return now > d.now;
    if( type_a != d.type_a ) return type_a > d.type_a;
    return type_b > d.type_b;
  }
};

Data arr[41];
bool cmp(Data &a, Data &b) {
  return a.cost < b.cost;
}

bool used[41][401][410];
void compute() {
  priority_queue<Data> Q;
  Q.push((Data){0,0,0,0});
  used[0][0][0] = true;
  while( !Q.empty() ) {
    Data d = Q.top(); Q.pop();
    if( d.type_a * Mb == d.type_b * Ma && d.type_a != 0 ) {
      cout << d.cost << endl;
      return;
    }
    if( d.now >= N ) continue;
    // 使わない
    if( !used[d.now+1][d.type_a][d.type_b] ) {
      used[d.now+1][d.type_a][d.type_b] = true;
      Q.push((Data){d.now+1,d.type_a,d.type_b,d.cost});
    }
    if( !used[d.now+1][d.type_a+arr[d.now].type_a][d.type_b+arr[d.now].type_b] ) {
      used[d.now+1][d.type_a+arr[d.now].type_a][d.type_b+arr[d.now].type_b] = true;
      Q.push((Data){d.now+1,d.type_a+arr[d.now].type_a, d.type_b+arr[d.now].type_b,d.cost+arr[d.now].cost});
    }
  }
  puts("-1");
}

int main() {
  cin >> N >> Ma >> Mb;
  rep(i,N) {
    cin >> a[i] >> b[i] >> c[i];
    arr[i].now = i;
    arr[i].type_a = a[i];
    arr[i].type_b = b[i];
    arr[i].cost = c[i];
  }
  sort(arr,arr+N);
  compute();
  return 0;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s,ss; cin>>s>>ss;
	
	int ct=0;
	for(int i=0; i<3; i++){
		if(s[i] ==ss[i])ct++;
	}
	writeln(ct);

}




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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF9=100000001,ID_MAX=20;
const long long int INF18=100000000000001;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}
//x^n mod m (nが負の時は０)
long myPow(long x, long n, long m){
  if(n<0)return 0;
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

const int H_MAX=10001,N_MAX=1001;
long int h,n,a[N_MAX],b[N_MAX],dp[N_MAX][H_MAX];

int main(){
    int i;
    //入力
    cin>>h>>n;
    rep(i,n){
        cin>>a[i+1]>>b[i+1];
    }
    rep(i,n+1){
        rep(j,h+1){
            if(j==0)dp[i][0]=0;
            else dp[i][j]=INF9;
        }
    }
    //処理
    for(int i=1;i<=n;i++){
        for(long int j=1;j<h+a[i];j++){
            long int res;
            if(j>h)res=dp[i][j-a[i]]+b[i];
            else if(j>=a[i])res=min(dp[i-1][j],dp[i][j-a[i]]+b[i]);
            else res=dp[i-1][j];
            if(dp[i][min(j,h)]>res)dp[i][min(j,h)]=res;
        }
    }
    //出力
    cout<<dp[n][h]<<endl;
}

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

const int MAXN = 2e5 + 10;
int A[MAXN];
int N;
long long res = 0;

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i)
		scanf("%d", A + i), A[i] -= i;
	sort(A + 1, A + N + 1);
	int b = A[N/2 + 1];
	for(int i =1; i <= N; ++i)
		res += abs(A[i] - b);
	cout<<res;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
//-4462 -3291 -3251 -2409 -679 3095 
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] ar = new int[n + 2];
		ar[0] = 0;
		ar[n+1] = 0;
		
		int total = 0;
		for (int i = 1; i < n + 1; i++) {
			ar[i] = scanner.nextInt();
			total += Math.abs(ar[i - 1] - ar[i]);
		}
		scanner.close();
		total += Math.abs(ar[n] - ar[n + 1]);
		
		for (int i = 1; i < n + 1; i++) {
			int a = Math.abs(ar[i-1] - ar[i + 1]);
			int b = Math.abs(ar[i] - ar[i - 1]) + Math.abs(ar[i] - ar[i + 1]);
			System.out.println(total + (a - b));
		}
	}

}


Measured memory_bytes: 65776
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define INFTY 999999



int main(void){
    int N,A,B;
    int max,min;

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

    if(A>=B){
        max=B;
    }
    else
    {
        max=A;
    }

    min= A+B-N;
    if(min<0){
        min=0;
    }
    
    printf("%d %d\n",max, min);
    
    return 0;
    
}


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

int main() {
    int N, a;
    cin >> N;
    deque<int> deq;
    for (int i = 0; i < N; i++) {
        cin >> a;
        int idx = lower_bound(deq.begin(), deq.end(), a) - deq.begin();
        if (idx) {
            deq[idx-1] = a;
        } else {
            deq.push_front(a);
        }
    }
    cout << deq.size() << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <stack>
using namespace std;
int n,m;
int a[1050];
int main()
{
	for (int i = 0; i < 1050; i++)
		a[i]=-1;
	cin>>n>>m;
	for (int i = 0; i < m; i++){
		int c,d;
		cin>>c>>d;
		a[c]=std::max(d,a[c]);
	}
	long long dist=0;
	for (int i = 0; i <= n; i++,dist++){
		//cout<<i<<' '<<dist<<endl;
		if(a[i]==-1)continue;
		int from=i;
		int to = a[i];
		for (int j = i+1; j <= n; j++){
			if(a[j]>to) to = a[j];
			else if(j==to){
				dist+=(to-from)*3;
				i=to;
				break;
			}

		}

	}
	cout<<dist<<endl;
	return 0;
}


Measured memory_bytes: 1164
def d_xxor(N, K, A):
    # bit_max = len(str(format(max(A), "b"))) + 1
    bit_max = 40
    ans = 0

    for j in range(bit_max, -1, -1):
        power = 1 << j
        # Aの各要素を2進表記したとき、i番目のビットに1は何個立つか？
        bit_count_1 = sum(1 for a in A if a & power != 0)

        # 解説における、「X_k=0とするか1とするか判定する」部分
        tmp = bit_count_1
        
        if power <= K and bit_count_1 <= N - bit_count_1:
            # X_k=1とした。XとKとの差を補正する。
            tmp = N - bit_count_1
            K -= power
        
        contribution = power * tmp
        ans += contribution  # 「b番目のビットがfに貢献する値」
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_xxor(N, K, A))


Measured memory_bytes: 14708