akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int r,g,b;
  cin>>r>>g>>b;
  cout<< ( ((g*10)+b)%4 ? "NO" : "YES" )<<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

typedef vector<int> vec;
typedef vector<vector<int>> mat;

int n, m, a, b, c, t;

mat mul(const mat& A, const mat& B) {
	mat C(A.size(), vec(B[0].size(), 0));
	for(int i = 0; i < (int)A.size(); ++i) {
		for(int k = 0; k < (int)B.size(); ++k) {
			for(int j = 0; j < (int)B[0].size(); ++j) {
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m;
			}
		}
	}

	return C;
}

mat pow(mat A, long long n) {
	mat B(A.size(), vec(A.size(), 0));
	for(int i = 0; i < (int)A.size(); ++i) {
		B[i][i] = 1;
	}

	while(n > 0) {
		if(n & 1) B = mul(B, A);
		A = mul(A, A);
		n >>= 1;
	}

	return B;
}

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

	while(cin >> n >> m >> a >> b >> c >> t && n) {
		vec s(n);
		for(int i = 0; i < n; ++i) {
			cin >> s[i];
		}

		mat matrix(n, vec(n, 0));
		for(int i = 0; i < n; ++i) {
			if(i) matrix[i - 1][i] = a;
			matrix[i][i] = b;
			if(i < n - 1) matrix[i + 1][i] = c;
		}

		matrix = pow(move(matrix), t);
		vector<int> ans(n, 0);
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				ans[j] += s[i] * matrix[i][j];
				ans[j] %= m;
			}
		}

		for(int i = 0; i < n; ++i) {
			cout << ans[i] << (i == n - 1 ? "\n" : " ");
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1280
function Scanner(input) {
	var self = this;
	self.itemNo = 0;
	self.orgStr = input;
	self.splitedStrs = (function(target) {
		var result = [];
		var target = target.replace(/[\n \t]+/g, " ");
		var strs = target.split(" ");
		for (var i = 0, len = strs.length; i < len; i++) {
			result.push(strs[i]);
		}
		return result;
	}(input));

	self.next = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? result : null;
	}

	self.nextInt = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseInt(result) : null;
	}

	self.nextBigDecimal = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseFloat(result) : null;
	}
	self.nextByte = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? new Int8Array(result) : null;
	}

}

// inputに入力データ全体が入る
function Main(sc) {

	var N = sc.nextInt();
	var K = sc.nextInt();
	var motteru = [];
	
	for (var i = 0; i < N; i++) {
		motteru.push(false);
	}
	
	for (var i = 0; i < K; i++) {
		var okasikosu = sc.nextInt();
		for (var j = 0; j < okasikosu; j++) {
			motteru[sc.nextInt() - 1] = true;
		}
	}
	
	var cnt = 0;
	for (var i = 0; i < motteru.length; i++) {
		if (!motteru[i]) cnt++; 
	}
	
	// 出力
	console.log(cnt);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("33"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得


Measured memory_bytes: 32636
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    long double A, B;
	cin >> A >> B;
	int C = A*B + 0.001;
	cout << C << endl;
}

Measured memory_bytes: 3708
S = list(input())
N = len(S)
num = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    num += int(S[i]) * d
    num %= 2019
    # num = (num + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[num] += 1
    d *= 10
    d %= 2019

ans = 0
for c in cnt:
    ans += c * (c-1) // 2
print(ans)

Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  int n,k;
  cin >> n >> k;
  ll ans = inf*100000;
  vi a(n+1);
  rep(i,n){
    int s;
    cin >> s;
    a[i] = s;
  }
  int p = lower_bound(ALL(a),0) - a.begin();
  a.insert(a.begin()+p,0);
  rep(i,n+1){
    int r = a[i];
    a[i] = abs(r);
    //cout << a[i] << endl;
  }
  //cout << a[p] << endl;
  rep(i,k+1){
    ll q;
    if(p+i>n || p-k+i<0) continue;
    if(a[p+i]>a[p-k+i])q=a[p+i]+2*a[p-k+i];
    else q=2*a[p+i]+a[p-k+i];
    ans = min(q,ans);
  }
  cout << ans << endl;
    
  
}




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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
LL gcd(LL a, LL b){return b?gcd(b,a%b):a;}

LL A[100001];
LL L_gcd[100001];
LL R_gcd[100001];

void solve()
{
  int N; cin >> N;
  LL ans = 0;
  
  REP1(i, N) 
  { 
      cin >> A[i];
      L_gcd[i] = gcd(L_gcd[i-1], A[i-1]);
  }

  RREP1(i, N)
  {
      R_gcd[i] = gcd(R_gcd[i+1], A[i]);
  }
  
  
  REP1(i, N) 
  { // A[i] を除外した場合における gcd
    
    ans = max(gcd(L_gcd[i], R_gcd[i+1]), ans);
  }
  cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 2560
# import sys
# input = sys.stdin.readline

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


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

n = int(input())
fri = [0]*(n+1)
for i in range(1, n+1):
    for j in range(i, n+1, i):
        fri[j] += 1
ans = 0
for i in range(1, n+1):
    ans += i * fri[i]
print(ans)






Measured memory_bytes: 146020
#include <stdio.h>

long long calc(long long a,long long b){
  if(b == 0) return 1;
  if(b%2 == 0){
    long long d = calc(a,b/2);
    return (d*d);
  }
  return (a*calc(a,b-1));
}

int main(void){
  long long N, P;
  scanf("%lld%lld", &N, &P);

  int A;
  int even = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &A);
    if(A%2 == 0) even++;
  }

  if(even == N && P == 1)
    printf("0\n");
  else if(even == N && P == 0)
    printf("%lld\n", calc(2, N));
  else
    printf("%lld\n", calc(2, N-1));

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

template<typename T> T find_first_positive(
    T const _b,
    T const _e)
    {
    auto b = _b, e = _e;
    if (*b>=0) return b;
    while(1) {
        size_t d = distance(b,e);
        if(d==2) {
            return b+1;
        }
        auto c = b+(d/2);
        if (*c>=0) {
            e = c+1;
        } else {
            b = c;
        }
    }
}

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    vector<long long> a(n);
    for(auto itr=a.begin();n>0;--n) {
        cin >> *itr; ++itr;
    }
    sort(a.begin(), a.end());
    if (*a.begin()>=0LL) {
        cout << accumulate(a.begin(), a.end(), 0LL) << endl;
    } else {
        auto p_itr = find_first_positive(a.begin(), a.end());
        if((distance(a.begin(), p_itr)&1)) {
            cout << accumulate(a.begin(), p_itr-1, 0LL) * -1LL + accumulate(p_itr+1,a.end(),0LL) +
                    abs(*(p_itr-1) + *p_itr) << endl;
        } else {
            cout << accumulate(a.begin(), p_itr, 0LL) * -1LL + accumulate(p_itr,a.end(),0LL) << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 1024
"""
寿司iまで歩いて食べに行くと、1~iまでの合計カロリー - iまでの移動距離　のカロリーを得られる。
円形なので、時計回りか反時計回りかで移動距離が変わるので、結果のカロリーも変わる。
愚直にやると、
・反時計回りの方向にL個、時計回りの方向にR個食べる
・先にLRどちらに食べに行くか
の選択があるので、N*N*2とかになり、間に合わない。
*2の部分は大したことないので、どちらを先に食べに行くかは全部やっても問題ない。
LとRの決め方について、例えばN=10として、先に左に２個食べる（L=2）とすると、Rは０～８の範囲で選べる。
入店位置から、時計回りに移動して食べて退店するまでのカロリーは、Lまで食べに行く時のカロリーと独立して考えられる。
各Lについてこれを毎回計算するのは処理が重複するので、
・入店位置からRまでのいずれかの寿司へ、時計回りに移動して食べられる時に得られる最大カロリー
を事前に計算しておいて、Lまで食べに行って戻ってきた時のカロリーと合わせればよい。
逆も同様。

これで*Nが一つ消える感じか。
"""
N,C = map(int, input().split())
clocks = [tuple(map(int, input().split())) for _ in range(N)]

antis = []
for x,v in reversed(clocks):
    antis.append((C-x, v))

accum_clocks = [0] * N
accum_clocks[0] = clocks[0][1] - clocks[0][0]
for i in range(1,N):
    accum_clocks[i] = accum_clocks[i-1] + clocks[i][1] - clocks[i][0] + clocks[i-1][0]

# 右にi個まで食べに行ける時に得られる最大カロリー
clocks_max = [0] * (N+1)

for i in range(N):
    clocks_max[i+1] = max(clocks_max[i], accum_clocks[i])

accum_antis = [0] * N
accum_antis[0] = antis[0][1] - antis[0][0]
for i in range(1,N):
    accum_antis[i] = accum_antis[i-1] + antis[i][1] - antis[i][0] + antis[i-1][0]

antis_max = [0] * (N+1)
for i in range(N):
    antis_max[i+1] = max(antis_max[i], accum_antis[i])


ans = 0
ans = max(ans, max(clocks_max), max(antis_max))

# 累積和をカロリーと距離に分けて保存しなかったために面倒になった。
accum_sushi = 0
for l in range(N):
    accum_sushi += antis[l][1]
    #print(l, antis[l][1] - 2*antis[l][0] , clocks_max[N-l-1])
    ans = max(ans, accum_sushi - 2*antis[l][0] + clocks_max[N-l-1])

accum_sushi = 0
for r in range(N):
    accum_sushi += clocks[r][1]
    #print(r, clocks[r][1] - 2*clocks[r][0] , antis_max[N-r-1])
    ans = max(ans, accum_sushi - 2*clocks[r][0] + antis_max[N-r-1])

    
print(ans)
"""
print(accum_clocks)
print(accum_antis)
print(clocks_max)
print(antis_max)
"""

Measured memory_bytes: 68696
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

int p[100001],r[100001];
void init(){rep(i,100001)p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  init();
  ll c[4];
  mem(c);
  rep(i,3) {
    int x,y;
    cin >> x >> y;
    unite(x-1,y-1);
    c[x-1]++;
    c[y-1]++;
  }
  set<int> s;
  rep(i,4) s.in(find(i));
  if(s.size()==1) {
    rep(i,4) {
      if(c[i]>=3) {
        pr("NO");
        return;
      }
    }
    pr("YES");
  } else pr("NO");
}

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


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

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

using namespace std;

int main() {
  while(1) {
    vector<pair<int,int>> mt;
    REP(i,2) {
      int n;
      cin >> n;
      if (!n) return 0;
      REP(j,n) {
        int h,r;
        cin>>h>>r;
        mt.emplace_back(h,r);
      }
    }
    sort(begin(mt),end(mt));
    int n = mt.size();
    vector<int> res(n);
    REP(i,n) {
      int mx = 0;
      REP(j,i) {
        if (mt[j].first < mt[i].first && mt[j].second < mt[i].second)
          mx=max(mx, res[j]);
      }
      res[i] = mx+1;
    }
    cout << *max_element(begin(res),end(res)) << endl;
  }
  return 0;
}

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

template<typename T>
struct Kruskal{
  
  struct edge{
    int from,to;
    T cost;
    int used;
    edge(int from,int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<int> r,p;
  vector<edge> es;

  Kruskal(){}
  Kruskal(int n):n(n),r(n,1),p(n){
    iota(p.begin(),p.end(),0);
  }
  
  int find(int x){
    if(x!=p[x]) p[x]=find(p[x]);
    return p[x];
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add(int u,int v,T c){
    es.emplace_back(u,v,c);
  }
  
  T build(){
    sort(es.begin(),es.end());
    T res=0;
    for(auto &e:es){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};

int main() {
    int V, E; cin >> V >> E;
    Kruskal<int> K(V);
    for (int i = 0; i < E; i++) {
        int a, b, c; cin >> a >> b >> c;
        K.add(a, b, c);
    }
    cout << K.build() << endl;
    return 0;
}


Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
int main(){
    int numofholiday, numofassignments, sumofdays = 0;
    cin >> numofholiday >> numofassignments;
    int assignments[numofassignments];
    for(int i = 0; i<numofassignments; i++){
        cin >> assignments[i];
        sumofdays = sumofdays+assignments[i];
    }
    if(sumofdays>numofholiday){
        cout << "-1";
    }
    if(sumofdays<=numofholiday){
        cout << numofholiday-sumofdays;
    }
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

vector<ll> memo(100, -1);

ll lucas(ll n) {
    if (memo[n] != -1)
        return memo[n];

    return memo[n] = lucas(n-1) + lucas(n-2);
}

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

    memo[0] = 2;
    memo[1] = 1;

    cout << lucas(N) << endl;

   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	int i, j, N;
	int l[100000] = { 0 }, r[100000] = { 0 };

	cin >> N;

	int a, b;
	int cnt = 0;
	for (i = 0; i < N; i++) {
		cin >> a >> b;
		cnt += b - a+1;
	}

	cout << cnt << endl;



	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);

        System.out.println(n % 2 == 0 ? n / 2 : (n / 2) + 1);

    }
}


Measured memory_bytes: 22356
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int done[55][55][55];
int go[55][55][55];

int ok(int u, int v, int lim) {
  if (done[u][v][lim]) {
    return go[u][v][lim];
  }
  if (u < v) {
    return 0;
  }
  if (u == v) {
    return 1;
  }
  for (int m = 1; m <= lim; ++m) {
    if (u % m == u) continue;
    if (ok(u % m, v, lim)) {
      go[u][v][lim] = 1;
      break;
    }
  }
  done[u][v][lim] = 1;
  return go[u][v][lim];
}

int oks(Int as, int b, int lim) {
  for (int a = 0; a <= 50; ++a) {
    if (as & (1LL << a)) {
      if (ok(a, b, lim)) {
        return 1;
      }
    }
  }
  return 0;
}

int A[55], B[55];
Int AS[55];

int main() {
  int N = in();
  for (int i = 0; i < N; ++i) {
    A[i] = in();
  }
  for (int i = 0; i < N; ++i) {
    B[i] = in();
    if (!ok(A[i], B[i], 50)) {
      puts("-1");
      return 0;
    }
  }

  Int res = 0;
  for (int i = 0; i < N; ++i) {
    AS[i] = 1LL << A[i];
  }

  for (int b = 50; b >= 1; --b) {
    bool ok_zero = true;
    for (int i = 0; i < N; ++i) {
      ok_zero &= oks(AS[i], B[i], b - 1);
    }
    if (!ok_zero) {
      res += 1LL << b;
      for (int i = 0; i < N; ++i) {
        for (int a = 0; a <= 50; ++a) {
          if (AS[i] & (1LL << a)) {
            AS[i] |= 1LL << (a % b);
          }
        }
      }
    }
  }

  printf("%lld\n", res);

  return 0;
}

Measured memory_bytes: 640
//階乗の末尾の０の個数
#include<iostream>

using namespace std;

int main(void){
	long long n;
	int ans=0;

	while(1){
		cin>>n;
		if(n==0)	break;
		while(n/5!=0){
			n/=5;
			ans+=n;
		}
		cout<<ans<<endl;
		ans=0;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
using PII = pair<int,int>;
using III = tuple<int,int,int>;

int solve(int N, int K, string &S){

	// cout<<S<<"\n";///

	S += S[N-1]=='0'? "1":"0";

	// cout<<S<<"\n";///

	vi ZO;//zero|one
	vi C;//count
	vi sumC;//累積和
	ZO.push_back(0);
	C.push_back(0);
	sumC.push_back(0);
	if(S[0]=='0'){
		ZO.push_back(1);
		C.push_back(0);
		sumC.push_back(0);
	}

	// vi ZO(1);//zero|one
	// ZO[0] = S[0]=='0'? 1:0;
	// vi C(1);//count
	// vi sumC(1);//累積和
	int zero = 0, one = 0;
	int count = 0;
	rpz(l, N){
		count++;
		if(S[l] != S[l+1]){
			// printf("Li %d L %c R %c count %d\n", l,S[l],S[l+1],count);//
			ZO.push_back(S[l]-'0');
			C.push_back(count);
			int end = sumC.size() - 1;
			if(end < 0) sumC.push_back(count);
			else sumC.push_back(count + sumC[end]);
			count = 0;
		}
	}

	int n = C.size();
	if(S[N-1]=='0'){
		ZO.push_back(!ZO[n-1]);
		C.push_back(0);
		sumC.push_back(sumC[n-1]);
		n = C.size();
	}

	// puts("--");//
	// rpz(i,C.size()){
	// 	printf("%d) z|o %d count %d sum %d\n",i,ZO[i], C[i],sumC[i]);
	// }puts("---");//

	int ans = 1;
	int width = K*2 + 1;
	if(width >= n) return N;

	for(int l=0, r=width; r<n; r+=2, l+=2){
		ans = max(ans, sumC[r]-sumC[l]);
	}

	return ans;
}

int main(){
	int N,K; cin>>N>>K;
	string S; cin>>S;
	ote(solve(N, K, S));
}


Measured memory_bytes: 1900
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

class LazySegmentTree {

	int[] nodes;
	int[] lazy;
	boolean[] isLazy;

	int n;
	int e; // 単位元

	public LazySegmentTree(int size) {
		n = 1;
		while (n < size) {
			n *= 2;
		}

		nodes = new int[2 * n - 1];
		lazy = new int[2 * n - 1];
		isLazy = new boolean[2 * n - 1];

		e = 0; // 単位元は0
	}

	private void eval(int k, int l, int r) {
		if (isLazy[k]) {

			// 葉でないなら
			if (r - l > 1) {
				// 子に伝搬
				lazy[2 * k + 1] = lazy[k] / 2;
				lazy[2 * k + 2] = lazy[k] / 2;

				isLazy[2 * k + 1] = true;
				isLazy[2 * k + 2] = true;
			}

			nodes[k] = lazy[k];

			lazy[k] = 0;
			isLazy[k] = false;
		}
	}

	private void update(int a, int b, int val, int k, int l, int r) {
		eval(k, l, r);
		if (a >= r || b <= l) {
			return;
		}

		if (a <= l && r <= b) {
			lazy[k] = (r - l) * val;
			isLazy[k] = true;
			eval(k, l, r);
			return;
		}

		update(a, b, val, 2 * k + 1, l, (l + r) / 2);
		update(a, b, val, 2 * k + 2, (l + r) / 2, r);

		nodes[k] = nodes[2 * k + 1] + nodes[2 * k + 2];

	}

	private int getSum(int a, int b, int k, int l, int r) {
		if (a >= r || b <= l) {
			return e;
		}

		eval(k, l, r);
		if (a <= l && r <= b) {
			return nodes[k];
		}

		int vl = getSum(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = getSum(a, b, 2 * k + 2, (l + r) / 2, r);

		return vl + vr;

	}

	public void update(int a, int b, int val) {
		update(a, b, val, 0, 0, n);
	}

	public int getSum(int a, int b) {
		return getSum(a, b, 0, 0, n);
	}

	public String debug() {
		StringBuffer buf = new StringBuffer();
		
		for(int s=0,n=1;s<nodes.length;s+=n,n*=2) {
			buf.append(_debug(nodes,s,s+n, this.n));
			buf.append("\n");
		}
		
		buf.append("--\n");
		
		for(int s=0,n=1;s<lazy.length;s+=n,n*=2) {
			buf.append(_debug(lazy,s,s+n, this.n));
			buf.append("\n");
		}
		return buf.toString();
	}
	
	private String _debug(int[] a, int s, int e, int x) {
		StringBuffer buf = new StringBuffer();
		for(int i=s;i<e;i++) {
			buf.append(a[i]);
			for(int j=0;j<(2*x)/(e-s) -1;j++) 
				buf.append(" ");
		}
		return buf.toString();
	}
	

	
}

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		LazySegmentTree seg = new LazySegmentTree(n);

		for (int i = 0; i < q; i++) {
			int c = sc.nextInt();
			if (c == 0) {
				int s = sc.nextInt();
				int t = sc.nextInt() + 1;
				int x = sc.nextInt();

				seg.update(s, t, x);

			} else {
				int s = sc.nextInt();
				int t = sc.nextInt() + 1;

				out.println(seg.getSum(s, t));
			}
		}

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}



Measured memory_bytes: 115980
//Keep Working Hard
  // I__Like__Food
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #pragma comment(linker, "/stack:200000000")
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define f first
  #define s second
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 3005
  #define INF 1e16
  const double PI = acos(-1);

  double dp[N][N];
int32_t main()
{



    int n;
    cin >> n;

    double p[n+1];

    for(int i = 1; i <= n; i++)
    {
      cin >> p[i];
    }

    dp[0][0] = (double)1;
    // dp[i][j] denotes the required probability if i throw i coins and j heads
    for(int i = 1; i <= n; i++)
    {
      for(int j = 0;  j <= i; j++)
      {
        dp[i][j] = dp[i-1][j-1]*(p[i]) + dp[i-1][j]*(1-p[i]);
        // sum from either head or tail at ith throw
      }
    }


         double ans = 0;

         for(int i = 1; i <= n; i++)
         {
          if(i > n - i)
          {
            ans += dp[n][i];
          }
         }

         cout << fixed << setprecision(12) << ans;




  return 0;
  
}  

Measured memory_bytes: 139264
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res * a;
		a = a * a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////

ll N, ans;
ll a[MAX_10p5 * 2], b[MAX_10p5 * 2];
ll ar[MAX_10p5 * 2], br[MAX_10p5 * 2];

ll solv(ll t) {
	ll ret = 0;
	repi(i, 0, N) {
		ar[i] = a[i] % (2 * t);
		br[i] = b[i] % (2 * t);
	}
	sort(br, br + N);
	repi(i, 0, N) {
		ll p1 = distance(br, lower_bound(br, br + N, 1 * t - ar[i]));
		ll p2 = distance(br, lower_bound(br, br + N, 2 * t - ar[i])) - p1;
		ll p3 = distance(br, lower_bound(br, br + N, 3 * t - ar[i])) - p1 - p2;
		ll p4 = N - p1 - p2 - p3;
		ret += (p2 + p4) % 2;
	}
	return ret % 2;
}

int main() {
	cin >> N;
	repi(i, 0, N) cin >> a[i];
	repi(i, 0, N) cin >> b[i];
	ll t = 1;
	repi(i, 0, 29) {
		ans += solv(t) * t;
		t *= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  vector<int>vec(4);
  string s;
  cin >> s;
  rep(i,4)vec[i]=s[i]-'0';
  int ans=vec[0];
  rep(i,2){
    rep(j,2){
      rep(k,2){
        ll res=ans;
        vector<char>c(3);
        if(i==0){
          res+=vec[1];
          c[0]='+';
        }
        else{
          res-=vec[1];
          c[0]='-';
        }
        if(j==0){
          res+=vec[2];
          c[1]='+';
        }
        else{
          res-=vec[2];
          c[1]='-';
        }
        if(k==0){
          res+=vec[3];
          c[2]='+';
        }
        else{
          res-=vec[3];
          c[2]='-';
        }
        if(res==7){
          cout << vec[0]<<c[0]<< vec[1] <<c[1] <<vec[2]<<c[2]<<vec[3] << "=7"<<endl;
          return 0;
        }
      }
    }
  }
        
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  cin >> S;
  const size_t N = S.size();

  vec<string> xss;
  for (int i = 0; i < (1 << N) / 2; i++) {
    string xs;
    for (int j = 0; j < N; j++) {
      xs.push_back(S[j]);
      if ((i >> j) & 0x01) {
        xs.push_back('+');
      }
    }
    xss.emplace_back(xs);
  }

  vec<string> res;
  ll answer = 0;
  for (auto&& xs : xss) {
    boost::algorithm::split(res, xs, boost::is_any_of("+"));
    vec<ll> ts;
    transform(ALL(res), back_inserter(ts), [](const string& s){ return stoll(s); });
    answer += accumulate(ALL(ts), 0ll);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d=0;
	cin>>n;
	vector <int> v(4);
	int i=3;
	while(n!=0)
	{
		v[i]=n%10;
		--i;
		n=n/10;
	}
	for(int i=0;i<3;++i)
	{
		if(v[i]==v[i+1])
		{
			++d;
		}
	}
	if(d==0)
	{
		cout<<"Good"<<endl;
	}
	else
	{
		cout<<"Bad"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int A, B;
    std::cin >> A >> B;

    int ret = 0;
    if (6 <= A && A <= 12) {
        ret = B / 2;
    } else if (A >= 13) {
        ret = B;
    }
    
    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    a_kinds = len(set(a))
    a_dup = n - a_kinds

    print(n-((a_dup+1)//2)*2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 58908
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

vector<VI> g;
VI dis;
int dfs(int now) {//now以降の最長パスを返す
    if (dis[now])return dis[now];
    int len = 0;
    for (int next : g[now])chmax(len, dfs(next) + 1);
    return dis[now] = len;
}

int main() {
    init();

    int n, m;
    cin >> n >> m;

    int x, y;
    g.resize(n);
    FOR(i, 0, m) {
        cin >> x >> y;
        g[--x].push_back(--y);
    }

    dis.resize(n, 0);
    int ans = 0;
    FOR(i, 0, n)if (!dis[i])chmax(ans, dfs(i));
    cout << ans << "\n";
}


Measured memory_bytes: 8192
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long n,q,k,x,y,z,a[500100][3],d[500100],first[500100];
void dfs(long long x,long long fa,long long ed) {
	d[x]=d[fa]+ed;
	for (int y=first[x];y;y=a[y][0]){
		long long tw=a[y][1];
		if (tw!=fa) dfs(tw,x,a[y][2]);
	}
}
int main() {
	scanf("%lld",&n);
	for (int i=1;i<n;i++) {
		scanf("%lld%lld%lld",&x,&y,&z);
		a[i*2-1][2]=a[i*2][2]=z;
		a[i*2-1][1]=y;
		a[i*2][1]=x;
		a[i*2-1][0]=first[x];
		a[i*2][0]=first[y];;
		first[x]=i*2-1;
		first[y]=i*2;
	}
	scanf("%lld%lld",&q,&k);
	dfs(k,0,0);
	for (int i=1;i<=q;i++) {
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",d[x]+d[y]);
	}
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    char c;
    cin >> c;

    if(c == 'A'){
        cout << 'T' << endl;
    }
    if(c == 'T'){
        cout << 'A' << endl;
    }
    if(c == 'C'){
        cout << 'G' << endl;
    }
    if(c == 'G'){
        cout << 'C' << endl;
    }
    return 0;
}

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() {
    double l; cin >> l;
    double x = l/3.0;
    double ans = x * x * x;
    printf("%.10f", ans);
}


Measured memory_bytes: 256
N=int(input())
bob=0
john=0
a=list(map(int,input().split()))
b=sorted(a)[::-1]
for i in range(N):
    if i==0 :
        bob+=b[i]
    else :
        if i%2==0 :
            bob+=b[i]
        else :
            john+=b[i]
print(bob-john)


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

vector<int> v[10];

int main() {
    int n, d; cin >> n >> d;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            int a; cin >> a;
            v[i].push_back(a);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int dist = 0;
            for (int k = 0; k < d; k++) {
                dist += (v[i][k]-v[j][k])*((v[i][k]-v[j][k]));
            }
            int s = sqrt(dist)+0.5;
            if (s*s==dist) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = input[0];
            var H = input[1];
            var maxA = 0;
            var thr = new int[N];

            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var a = input[0];
                var b = input[1];
                if (a > maxA) maxA = a;
                thr[i] = b;
            }

            Array.Sort(thr);
            Array.Reverse(thr);
            var cnt = 0;

            for (int i = 0; i < N; i++)
            {
                if (thr[i] > maxA)
                {
                    H -= thr[i];
                    cnt++;
                    if (H <= 0)
                    {
                        Console.WriteLine(cnt);
                        return;
                    }
                }else
                {
                    break;
                }
            }

            cnt += H / maxA;
            if (H % maxA != 0) cnt++;

            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 17628
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    long long int x,y;
  	cin>>x>>y;
  	int count=0;
  	long long int temp=x;
  	while(y-temp>=0){
      temp=temp*2;
      count++;
    }
  cout<<count;
    return 0;
}

Measured memory_bytes: 256
function main(input) {
  const a = input[0].split(" ");
  const num = input[1].split(" ");
  const u = input[2];
  
  num[0] = num[0] - 0;
  num[1] = num[1] - 0;
  
  if(a[0]===u){
    num[0]--;
   }else{
     num[1]--;
     }
  
  console.log(num[0]+" "+num[1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#include<fstream>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define mod 1000000007
#define All(v) v.begin(),v.end()

using namespace std;
int n;
int ma,mb;
int a[50],b[50],c[50];
int dp[50][405][405];

int solve(int i,int x,int y)
{
    if(i == n)
    {
        int G = __gcd(x,y);
       // cout << G << endl;
        if(G)
        {
            x /= G;
            y /= G;
            if(x == ma && y == mb)
                return 0;
        }
        return 1e9;
    }
    int &ret = dp[i][x][y];

    if(ret != -1)
        return ret;


    int x1 = solve(i+1,x,y);

    int r1 = x + a[i];
    int r2 = y + b[i];

    int x2 = c[i] + solve(i+1,r1,r2);
    return ret = min(x1,x2);
}

int main()
{
    cin >> n >> ma >> mb;
    for(int i=0; i<n; i++)
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    memset(dp,-1,sizeof(dp));

    int ans = solve(0,0,0);
    if(ans >= 1e9)
        cout << -1 << endl;
    else
        cout << ans << endl;










    return 0;
}



Measured memory_bytes: 32384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//solve

// int D
void solve(void)
{
  string S,T; cin>>S; cin>>T; 
  int A,B; cin>>A; cin>>B; 
  string U; cin>>U;
  if(U == S) A--;
  else if (U == T)B --;
  cout<<A<<" "<<B<<endl;


  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		
		int n = 0;
		try {
			n = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		int [] w = new int[n];
		
		try {
			String str = br.readLine();
			String [] strs = str.split(" ");
			for(int i = 0; i < n; i++) {
				w[i] = Integer.parseInt(strs[i]);
			}
			br.close();
		} catch  (IOException e){
			e.printStackTrace();
		}
		
		int min = Math.abs(w[0] - Sum(1, n-1, w));
		
		for(int i = 1; i < n; i++) {
			int sum;
			if(min > (sum = Math.abs(Sum(0, i, w) - Sum(i+1, n-1, w)))) {
				min = sum;
			}
		}
		
		System.out.println(min);
	}
	
	static int Sum(int a, int n, int[] w){
		int sum = 0;
		for(int i = a; i <= n; i++) {
			sum += w[i];
		}
		return sum;
	}
}

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

using namespace std;

int main(){

  int n;

  while(1){

	cin >> n;

	if(n == 0)
	  break;

	int state = 0;
	int stt_r = 0;
	int stt_l = 0;
	int cnt = 0;
	string f;

	for(int i = 0;i < n;++i){
	  cin >> f;

	  if(f == "lu")
		stt_l = 1;
	  else if(f == "ru")
		stt_r = 1;
	  else if(f == "ld")
		stt_l = 0;
	  else if(f == "rd")
		stt_r = 0;

	  if(state == 0 && stt_l == 1 && stt_r == 1){
		cnt++;
		state = 1;
	  }
	  else if(state == 1 && stt_l == 0 && stt_r == 0){
		cnt++;
		state = 0;
	  }
	  
	}
	cout << cnt << endl;
  }

}


Measured memory_bytes: 3120
n,m=map(int,input().split())
A = list(map(int,input().split()))
B=[]
for i in range(m):
    B.append(list(map(int,input().split())))
A.sort()
B.sort(key=lambda B: B[1], reverse=True)

i=j=0
ans = sum(A)
while j<n:
    newv = B[i][1]
    newc = min(B[i][0],n-j)
    if newv>A[j] :
        for k in range(newc):
            if newv<=A[j+k]:
                break
        else:
            k+=1
        ans+=newv*(k)-sum(A[j:j+k])
        i+=1
        j+=k
    else:
        break
    if i>=m :
        break

print(ans)

Measured memory_bytes: 32944
#include <cstdio>
#include <iostream>
#include <cstring>
#define MN 201000

typedef long long ll;
int fa[MN];
int c1[MN], c2[MN];
int Min[MN];
ll D; int a[MN];
int X[MN], Y[MN];
int x[MN], y[MN];
ll ans = 0;
int bl;
int n;

int Abs(int a) {return a > 0 ? a : -a;}
ll F(int i) {return i ?  i * D + a[i] : 1e18;}
ll G(int i) {return i ? -i * D + a[i] : 1e18;}
ll H(int i, int j) {if(i == 0 || j == 0) return 1e18; return Abs(i - j) * D + a[i] + a[j];}

void add(int *c, int x, int v, int type)
{
    for(int i = x; i <= n; i += i & -i)
    {
        if(!type) if(F(v) < F(c[i])) c[i] = v;
        if( type) if(G(v) < G(c[i])) c[i] = v;
    }
}

int query(int *c, int x, int type)
{
    int ans = 0;
    for(int i = x; i; i -= i & -i)
    {
        if(!type) if(F(c[i]) < F(ans)) ans = c[i];
        if( type) if(G(c[i]) < G(ans)) ans = c[i];
    }
    return ans;
}

int Find(int x) {return fa[x] == x ? x : fa[x] = Find(fa[x]);}

void solve()
{
    memset(x, 0, sizeof x);
    memset(y, 0, sizeof y); 
    memset(c1, 0, sizeof c1);
    memset(c2, 0, sizeof c2);
    memset(Min, 0, sizeof Min);
    for(int i = 1; i <= n; i++)
    {
        int u = Find(i);
        int x = query(c1, u - 1, 1);
        int y = query(c2, n - u, 1);
        if(G(x) > G(y)) x = y;
        if(H(x, i) <= H(Min[i], i)) Min[i] = x;
        add(c1, u, i, 1);
        add(c2, n - u + 1, i, 1);
    }
    memset(c1, 0, sizeof c1);
    memset(c2, 0, sizeof c2);
    for(int i = n; i >= 1; i--)
    {
        int u = Find(i);
        int x = query(c1, u - 1, 0);
        int y = query(c2, n - u, 0);
        if(F(x) > F(y)) x = y;
        if(H(x, i) <= H(Min[i], i)) Min[i] = x;
        add(c1, u, i, 0);
        add(c2, n - u + 1, i, 0);
    }
    for(int i = 1; i <= n; i++)
    {
        int u = Find(i);
        if(H(i, Min[i]) < H(x[u], y[u])) x[u] = i, y[u] = Min[i];
    }
    int tot = 0;
    for(int i = 1; i <= n; i++)
    {
        int u = Find(i);
        ++tot; X[tot] = x[u]; Y[tot] = y[u];
    }
    for(int i = 1; i <= tot; i++)
    {
        int x = Find(X[i]), y = Find(Y[i]);
        if(x == y) continue;
        ans += H(X[i], Y[i]);
        fa[x] = y;
        bl--;
    }
}

int main()
{
    scanf("%d%lld", &n, &D);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]), fa[i] = i;
    bl = n;
    while(bl > 1) solve();
    printf("%lld\n", ans);
}

Measured memory_bytes: 10244
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
vi a;
rep(i,3){
int t;
cin>>t;
a.push_back(t);
}
sort(a.begin(),a.end());
cout<<a[0]+a[1]<<endl;
	return 0;
}



Measured memory_bytes: 256