akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

int main() {
	SS(int,N,a,b);
	SS(string,s);
	rep(i,N){
		if(s[i]=='a'&&a+b>0){
			p("Yes");
			a--;
		}
		else if(s[i]=='b'&&b>0&&a+b>0){
			p("Yes");
			b--;
		}
		else p("No");
	}
}

Measured memory_bytes: 848
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int s;
const int mod=1e9+7;
int add(int &x,int y){
  x+=y;
  if(x>=mod)x-=mod;
}
int dp[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>s;dp[0]=1;
  for(int i=0;i<=s;i++){
    for(int j=3;j+i<=s;j++){
     ( dp[j+i]+=dp[i] )>=mod && (dp[j+i]-=mod);
//      add(dp[j+i],dp[i]);
    }
  }
  cout<<dp[s]<<'\n';
  return 0;
}

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

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

int main() {
    int n;
    double m, d; cin >> n >> m >> d;
    double ans = 0;
    if(d == 0){
    cout << setprecision(numeric_limits<double>::max_digits10) << (m - 1) / n;
    return 0;
    }else{
        if(n % 2 == 0){
            FOR(i, 1, n / 2 + 1){
                if(i + d <= n){ans ++;}
                if(i - d >= 1){ans ++;}
            }
            ans *= 2;
        }else if(n % 2 == 1){
            FOR(i, 1, n / 2 + 1){
                if(i + d <= n){ans ++;}
                if(i - d >= 1){ans ++;}
            }
            ans *= 2;
            if(n > 1 && n / 2 + 1 + d <= n){
                ans += 2;
            }
        }

    }
    cout << setprecision(numeric_limits<double>::max_digits10) << ((ans) / n ) * ((m - 1) / n);
}

Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__);
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__);


#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){

    SCIN(s);
    Yes(s[0]==s[1]&&s[0]==s[2]||s[1]==s[2]&&s[1]==s[3]);
    




    return 0;
}


Measured memory_bytes: 256
package main

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

type heap struct {
	pos  int
	data []int
}

func newHeap() *heap {
	var h heap
	h.pos = 0
	h.data = make([]int, 0)
	return &h
}
func (h *heap) push(v int) {
	me, parent := h.pos, (h.pos-1)/2
	if me < len(h.data) {
		h.data[me] = v
	} else {
		h.data = append(h.data, v)
	}
	h.pos++
	for me > 0 {
		if h.data[parent] <= h.data[me] {
			break // 自分の値が親の値より等しいか大きい(ヒープの条件を満たす)
		}
		// 親と自分の位置を入れ替える
		h.data[parent], h.data[me] = h.data[me], h.data[parent]
		me = parent
		parent = (me - 1) / 2
	}
}
func (h *heap) peek(v *int) bool {
	if h.pos <= 0 {
		return false
	}
	*v = h.data[0]
	return true
}
func (h *heap) pop(v *int) bool {
	if h.pos <= 0 {
		return false
	}
	*v = h.data[0] // ルートの値を取り出す(定義により常に最小値)
	h.pos--
	h.data[0] = h.data[h.pos] // その時点の最後尾のデータを先頭に持ってくる
	me := 0                   // 根から始める
	const inf = int(1e18)
	for me < h.pos { // どこに配置すれば良いか根からたどる
		lchp, rchp := 2*me+1, 2*me+2 // pの左の子どもは2*p+1, 右の子どもは2*p+2の位置にある(heapの定義により)
		lchv, rchv := inf, inf       // それぞれ、左の子の値と、右の子の値
		if lchp < h.pos {
			lchv = h.data[lchp]
		}
		if rchp < h.pos {
			rchv = h.data[rchp]
		}
		if h.data[me] <= lchv && h.data[me] <= rchv {
			// この位置でOKであればここでおしまい
			break
		}
		// 以下の処理で親子を入れ替える
		if lchv < rchv { // 左の子 < 右の子
			h.data[me], h.data[lchp] = h.data[lchp], h.data[me]
			me = lchp
		} else {
			h.data[me], h.data[rchp] = h.data[rchp], h.data[me]
			me = rchp
		}
	}
	return true
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	pqs := make([]*heap, n)
	for i := 0; i < n; i++ {
		pqs[i] = newHeap()
	}
	q := nextInt(sc)
	ans := make([]int, 0)
	for i := 0; i < q; i++ {
		op := nextInt(sc)
		t := nextInt(sc)
		var v int
		if op == 0 {
			x := nextInt(sc)
			pqs[t].push(-x) // 逆順なので符号反転してpushする
		} else if op == 1 {
			if pqs[t].peek(&v) {
				ans = append(ans, -v) //逆順なので符号反転して追加
			}
		} else {
			pqs[t].pop(&v)
		}
	}
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}



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

using namespace std;

int N;
vector<int> X;



int main()
{

	cin >> N;

	X = vector<int>(N);

	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}

	sort(X.begin(), X.end());

	int ans = 0;


	for (int i = 0; i < N; i++) {
		ans += (X[i] - X[0]) * (X[i] - X[0]);
	}

	for (int j = X[0] + 1; j <= X[N - 1]; j++) {
		int tmp = 0;
		for (int i = 0; i < N; i++) {
			tmp += (X[i]-j) * (X[i] - j);
		}

		ans = min(ans,tmp);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vi A;
ll n,m;
bool check(ll mid){
  ll now=1;
  ll hoge=0;
  ll cnt=0;
  priority_queue<ll>que;
  priority_queue<ll,vi,greater<>>que2;
  while(now+mid<=A[n-1]){
    while(!que2.empty()&&que2.top()<now){
      que.push(que2.top());
      que2.pop();
    }
    while(hoge<n&&now+mid>A[hoge]){
      if(A[hoge]<now)que.push(A[hoge]);
      else que2.push(A[hoge]);
      hoge++;
      // cout<<now<<" "<<mid<<" "<<hoge<<endl;
    }
    if(hoge==0)return false;
    if(!que.empty()&&!que.empty()){
      now+=max(1LL,max(mid-abs(now-que.top()),mid-abs(now-que2.top())));
    }else if(!que.empty()){
      now+=max(1LL,mid-abs(now-que.top()));
    }else if(!que2.empty()){
      now+=max(1LL,mid-abs(now-que2.top()));
    }
    
    cnt++;
    //  if(mid==5)
    //cout<<now<<" "<<cnt<<" "<<hoge<<endl;
  }
  cnt++;

  if(cnt<m)return false;
  else return true;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(cin>>n>>m,n+m){
    A.resize(n);
    for(int i=0;i<n;i++){
      cin>>A[i];
    }
    ll ma=-1;
   
    ll le=A[0]-1,ri=1e6+1;
    while(ri-le>1){
      ll mid=(ri+le)/2;
      if(check(mid))le=mid;
      else ri=mid;
    }
    if(le>=A[0])ma=max(ma,le);
    cout<<ma<<endl;
  }
  return 0;
}



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

int main(){
	int d;
	cin >> d;
	switch (d) {
	case 25:
		cout << "Christmas" << endl;
		break;
	case 24:
		cout << "Christmas Eve" << endl;
		break;
	case 23:
		cout << "Christmas Eve Eve" << endl;
		break;
	case 22:
		cout << "Christmas Eve Eve Eve" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include<iostream>

int min(int a,int b);

int main(){
  int maxProf;
  int minPrice;//区間ないの最小の数

  int N;
  int *A ;

  std::cin >> N;
  A = new int[N];

  for(int i = 0; i < N; i++)
  {
    std::cin >> A[i];
  }

  int candidateProf;
  for(int i = 1; i < N; i++)
  {
      if(i == 1){
        maxProf = A[i] - A[i-1];
        minPrice = min(A[i],A[i-1]);
        continue;
      }
      candidateProf = A[i] - minPrice;
      if(maxProf < candidateProf){
        maxProf = candidateProf;
      }
      if(A[i] < minPrice){
        minPrice = A[i];
      }
  }

  std::cout << maxProf << std::endl;

  return 0;
}

int min(int a, int b){
  if(a <= b) return a;
  return b;
}



Measured memory_bytes: 3872
M, D = map(int, input().split())
d1 = D % 10
d2 = D // 10
ans = 0
if d2 < 2:
    print(0)
    exit(0)
for i in range(2, d2):
    for j in range(2, 10):
        if i * j <= M:
            ans += 1
        else:
            break
for j in range(2, d1 + 1):
    if d2 * j <= M:
        ans += 1
    else:
        break
print(ans)


Measured memory_bytes: 3060
s=list(str(input()))
l=[]
for i in range(len(s)):
    if s[i]=="A" or s[i]=="T" or s[i]=="G" or s[i]=="C":
        l.append(1)
    else:
        l.append(0)
tl=[]
for k in range(len(l)):
    ctr=0
    for i in range(k,len(l)):
        if l[i]==1:
            ctr+=1
        else:
            break
    tl.append(ctr)
print(max(tl))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,cnt[4],vis[305][305][305];
double dp[305][305][305];
double solve(ll i,ll j,ll k){
    double tot = i+j+k;
    if(i<0 || j<0 || k<0 || tot==0)return 0;
    if(vis[i][j][k])return dp[i][j][k];
    vis[i][j][k]=1;
    return dp[i][j][k] = (n + (i*solve(i-1,j,k)) + (j*solve(i+1,j-1,k)) + (k*(solve(i,j+1,k-1))) )/tot;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=0,x;i<n;i++)cin>>x,cnt[x]++;
    cout<<fixed<<setprecision(15)<<solve(cnt[1],cnt[2],cnt[3]);
}



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

template <typename T>
struct Matrix {
    vector<vector<T>> mat;
    Matrix(int n, int m, T val = 0) : mat(n, vector<long long>(m, val)) {};
    void init(int n, int m, T val = 0) {mat.assigin(n, vector<long long>(m, val));}
    size_t size() const {return mat.size();}
    inline vector<long long>& operator[](int i) {return mat[i];}
};

long long MOD;

template <typename T>
Matrix<T> operator*(Matrix<T> A, Matrix<T> B) {
    Matrix<T> C(A.size(), B[0].size());
    for(int i = 0; i < A.size(); ++i) {
        for(int j = 0; j < B[0].size(); ++j) {
            for(int k = 0; k < B.size(); ++k) {
                C[i][j] = (C[i][j] + A[i][k] * B[k][j] % MOD) % MOD;
            }
        }
    }
    return C;
}

template <typename T>
Matrix<T> pow(Matrix<T> A, long long n) {
    Matrix<T> C(A.size(), A.size());
    for(int i = 0; i < A.size(); ++i) C[i][i] = 1;
    while(n > 0) {
        if(n & 1) C = C * A;
        A = A * A;
        n >>= 1;
    }
    return C;
}

using mat = Matrix<long long>;
using vec = vector<long long>;

vec pro(mat A, vec X, long long C){
    vec ret(3, 0);
    mat Apro = pow(A, C);

    for(int i=0; i<3; ++i) {
        for(int j=0; j<3; ++j) {
            ret[i] = (ret[i] + Apro[i][j] * X[j] % MOD) % MOD;
        }
    }
    return ret;
}

long long powmod(long long x, long long n) {
    long long ret = 1;
    while(n > 0) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

int main() {
    long long L, A, B;
    cin >> L >> A >> B >> MOD;

    int start = 0;
    long long tmp = 1;
    for(; start < 18; ++start) {
        if(A >= tmp && A < tmp * 10) break;
        tmp *= 10;
    }

    vec C(18);
    long long prev = A - B, cnt = 0;

    for(int i=start; i<18; ++i) {
       C[i] = ((long long)pow(10, i + 1) - prev) / B;
       if(prev + B * C[i] == (long long)pow(10, i + 1)) --C[i];
       C[i] = min(C[i], L - cnt);
       cnt += C[i];
       if(cnt == L) break;
       prev += B * C[i];
    }

    vec X = {0, A, B};
    mat coeff(3, 3);
    coeff[0] = {1, 1, 0};
    coeff[1] = {0, 1, 1};
    coeff[2] = {0, 0, 1};
    for(int d=0; d<18; ++d) {
        coeff[0][0] = powmod(10, d + 1);
        X = pro(coeff, X, C[d]);
    }

    cout << X[0] % MOD << endl;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if(i%2!=0)
        {
            if(s[i]=='R')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if(s[i]=='L')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
#define INF 1000
#define F first
#define S second
int n,ans;
P a[105],b[105];
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i].F,&a[i].S);
    }
    for(int i=0;i<n;i++){
        scanf("%d%d",&b[i].F,&b[i].S);
    }
    sort(a,a+n);
    sort(b,b+n);
    vector<int>o;
    int e=0;
    for(int i=0;i<n;i++){
        int x=b[i].F,y=b[i].S;
        while(e<n&&a[e].F<x){
            o.push_back(a[e].S);
            e++;
        }
        if(o.size()==0)continue;
        sort(o.begin(),o.end(),greater<int>());
        for(int j=0;j<o.size();j++){
            if(o[j]<y){
                ans++;
                o[j]=INF;
                break;
            }
        }
    }
    printf("%d\n",ans);
}


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

int main() {
	ll n, a[4000],ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i];
	}
	ans -= n;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = list(map(int, input().split()))
for k in range(N):
  a[k] //= 2

foo = 1
while a[0]%2 == 0:
  foo *= 2
  a[0] //= 2
for k in range(1, N):
  if a[k] % foo == 0 and a[k]%(2*foo) !=0:
    a[k] //= foo
    continue
  else:
    print(0)
    exit()
ans = 0

import math
lcm = a.pop()
for k in range(1, N):
  b = a.pop()
  lcm = lcm * b // math.gcd(lcm, b)
  if lcm* foo > M:
    print(0)
    exit()
lcm *= foo
ans = int((M / lcm -1)//2 + 1)
print(ans)

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

import static java.lang.Integer.parseInt;

/**
 * Alphametic - Accepted
 */
public class Main {

	static int[] nums;
	static boolean[] used;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		words = br.readLine().split(" ");

		nums = new int[9];
		used = new boolean[10];

		for (int i = 0; i < words.length; i++) {
			nums[i] = parseInt(words[i]);
			if (nums[i] != -1) used[nums[i]] = true;
		}

		System.out.println(solve(0));
	}

	static int solve(int idx) {

		if (idx == nums.length) {
			if (check()) return 1;
			else return 0;
		}

		//
		int ret = 0;

		if (nums[idx] == -1) {
			for (int k = 1; k <= 9; k++) {
				if (!used[k]) {
					nums[idx] = k;
					used[k] = true;
					ret += solve(idx + 1);
					nums[idx] = -1;
					used[k] = false;
				}
			}
		} else {
			ret = solve(idx + 1);
		}

		return ret;
	}

	static boolean check() {

		return nums[0]
				+ nums[1] * 10 + nums[2]
				+ nums[3] * 100 + nums[4] * 10 + nums[5]
				== nums[6] * 100 + nums[7] * 10 + nums[8];
	}
}

Measured memory_bytes: 25848
march = "MARCH".split("");

N = gets.to_i
cnt_by_ini = {}
march.each do |c| cnt_by_ini[c] = 0 end
N.times do
    ini = gets[0]
    cnt_by_ini[ini] += 1 if cnt_by_ini.key?(ini)
end

ans = 0
march.combination(3).each do |initials|
    pattern = 1
    initials.each do |ini|
        pattern *= cnt_by_ini[ini]
    end
    ans += pattern
end
puts ans

Measured memory_bytes: 2044
from _collections import deque
H, W = map(int, input().split())
maze = []
wall = 0
for i in range(H):
    s = input()
    maze.append(s)
    wall += s.count('#')

queue = deque()
queue.append([0,0])
steps = [[-1]*W for _ in range(H)]
steps[0][0] = 0
while queue:
    now = queue.popleft()
    #print("now=" + str(now))

    UDLR = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    for direction in UDLR:
        goto_y = now[0] + direction[0]
        goto_x = now[1] + direction[1]
        if (goto_x - 0)*(W-1 - goto_x) < 0 or (goto_y - 0)*(H-1 - goto_y) < 0:
            continue
        if maze[goto_y][goto_x] == '#' or steps[goto_y][goto_x] >= 0:
            continue

        queue.append([goto_y, goto_x])
        steps[goto_y][goto_x] = steps[now[0]][now[1]] + 1

#print("\n".join(map(str, steps)))
if steps[H-1][W-1] == -1:
    print(-1)
    exit()

print(H*W - wall - steps[H-1][W-1] - 1)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct SandGlass { 
  ll t, up, lo, ma, mi, d, now; 
  bool operator< (const SandGlass &x) const { return t<x.t; }
};

int main() {
  ll X, K; cin >> X >> K;
  ll r[K+2] = {}; rep(i,K) cin >> r[i+1]; r[K+1] = INF;

  vector<SandGlass> sg(K+2);
  ll now = 0;
  rep(i,K+2) {
    if (i==0) sg[0] = {0,X,0,X,0,-1,now};
    else {
      ll rd = r[i] - r[i-1];
      if (i%2==1) {
        now -= rd;
        sg[i].t = r[i];
        sg[i].up = sg[i-1].up;
        sg[i].lo = max(sg[i-1].lo,-1*now);
        sg[i].ma = max((ll)0,sg[i-1].ma-rd);
        sg[i].mi = max((ll)0,sg[i-1].mi-rd);
        sg[i].d = 1;
        sg[i].now = now;
      }
      else {
        now += rd;
        sg[i].t = r[i];
        sg[i].up = min(sg[i-1].up,X-now);
        sg[i].lo = sg[i-1].lo;
        sg[i].ma = min(X,sg[i-1].ma+rd);
        sg[i].mi = min(X,sg[i-1].mi+rd);
        sg[i].d = -1;
        sg[i].now = now;
      }

    }
  }
  // for (auto x: sg) cout << x.t << "->" << x.up << " " << x.lo << " " << x.ma << " " << x.mi << endl;

  ll Q; cin >> Q;
  rep(i,Q) {
    ll t, a; cin >> t >> a;
    SandGlass now = *(upper_bound(all(sg),(SandGlass){t,0,0,0,0,0})-1);
    ll result = 0;
    if (now.ma<=now.mi) {
      if (now.d==1) result = min(X, now.ma+(t-now.t));
      else result = max((ll)0, now.ma-(t-now.t));
    }
    else {
      a = max(min(a,now.up),now.lo);
      // cout << now.up << "-" << a << "-" << now.lo << endl;
      if (now.d==1) result = min(X, a+now.now+(t-now.t));
      else result = max((ll)0, a+now.now-(t-now.t));
    }
    cout << result << endl;
  }
  // cout << result << endl;
  return 0;
}

Measured memory_bytes: 7424
// ABC161B.cpp
//#include "pch.h"
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <numeric> // accumulate
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int>A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end(), greater<int>());
    int sum = accumulate(A.begin(), A.end(), 0);
    // if(A.at(M-1)<sum/(4*M)) { "No" } else { "Yes" }とすると間違い
    // sum/(4*M)は実数で、c++では小数点以下が切り捨てられて整数となる。
    // 例えば、10/4は2.5だが、小数点以下が切り捨てられて2となる。
    // 2<2.5で条件が成り立たず、この式では2<2となり"Yes"になる。
    // if(A.at(M-1)>=sum(4*M)) {"Yes" } else {"No" }も同様。
    // A.at(M-1)*4*Mのように、移項して整数化して対応するのが良い。
    if (A.at(M - 1)*4*M >=sum)
    {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

using namespace std;

int main(){
    int N;
    cin>>N;
    vector <int>A(N);
    for(int i=0 ; i<N ; i++){
        cin>>A[i];
    }
    int ans = 0;
    for(int i=0 ; i<N ; i++){
        if(A[i]%2==1)continue;
        while(1){
            ans += 1;
            A[i]/=2;
            if(A[i]%2==1)break;
        }  
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;


int main() {
	int n;
	string s;
	cin >> n >> s;
	if (n % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	string x = s.substr(0,n/2);
	if (x + x == s) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    ll a[n];
    rep(n) cin >> a[i];
    ll ans = 0;
    rep(n){
        ans += a[i]-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define INF (1LL << 31)
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

int main()
{
    ll n; cin >> n;
    VI a(n + 1); rep(i, n + 1) cin >> a[i];

    VI b(n + 1);
    b[n] = a[n];
    for (int i = n; i > 0; --i) {
        b[i - 1] = b[i] + a[i - 1];
    };

    ll ans = 0;
    ll m = 1; // ある深さの頂点の最大値
    rep(i, n + 1) {
        
        if (a[i] > m) {
            ans = -1;
            break;
        }
        m = min(m, b[i]);
        ans += m;
        m -= a[i];
        m *= 2;

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


Measured memory_bytes: 4836
import sys
input = sys.stdin.readline
from collections import Counter

mod = 998244353

def power_func(a,n,mod):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

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

A = Counter(D)
B = sorted(A.items())

if D[0] != 0:
    print(0)
else:
    ans = 1
    for i, (k, num) in enumerate(B):
        if i == 0:
            if num != 1:
                ans = 0
                break
            pre = 0
            continue
        if k != pre + 1:
            ans = 0
            break
        if k == 1:
            pre = 1
            p = num
            continue
        ans = ans * power_func(p, num, mod) % mod
        p = num
        pre = k
    
    print(ans)
    

Measured memory_bytes: 21532
fun main(args: Array<String>) {
  val N = readInt()
  val X = readInts()

  var min = Long.MAX_VALUE
  for (i in 1..100) {
    var sum = 0L
    for (j in 0 until N) {
      val x = X[j]
      sum += (x - i) * (x - i)
    }
    min = Math.min(min, sum)
  }
  println(min)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 36000
#include<bits/stdc++.h>
#define maxn 3200
using namespace std;
typedef long long LL;
char s[maxn], t[maxn];
int f[maxn][maxn];
int main(){
	ios::sync_with_stdio(false);
	cin >> s + 1 >> t + 1;
	int n = strlen(s + 1), m = strlen(t + 1);
	for(int i = 1; i <= n; i += 1)
		for(int j = 1; j <= m; j += 1)
			if(s[i] == t[j]) f[i][j] = f[i - 1][j - 1] + 1;
			else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
	string ans;
	while(f[n][m]){
		if(s[n] == t[m]){
			ans.push_back(s[n]);
			n -= 1;
			m -= 1;
		}
		else if(f[n - 1][m] == f[n][m]) n -= 1;
		else m -= 1;
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
} 

Measured memory_bytes: 39168
#pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<double> list(N+1,9999
  );
  for (int i = 0; i < N; i++) {
    cin >> list[i];
  }
  sort(all(list));
  dout << "====listの内容====\n";
  for (int i = 0; i < N; i++) dout << list[i] << endl;
  dout << "====ここまで====\n";
  rep(i, N-1) { 
    dout << i << "/" << list[i] << "/" << list[i+1] << endl;
    list[i + 1] = (list[i] + list[i+1])/2;
  }
  cout << list[N-1];
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin >> n;
    ll last = 0;
    ll res = 0;
    for(int i = 0;i < n;i++){
        ll in;
        cin >> in;
        if(last > in){
            res += last - in;
        }
        else{
            last = in;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

#define Num 200000

int main(void){

    int s[Num], t[Num];
    int n, q, i, j, right, left, mid, count = 0;

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

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

    
    for (i=0; i<q; i++) {
        left = 0;
        right = n;
        while (left < right) {
            mid = (right+left)/2;
            if (s[mid] == t[i] || s[mid+1] == t[i]) {
                count++;
                break;
            } else if (t[i] < s[mid]) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
    }

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

  return 0;
}


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

int main(){
	int N, M, C, index = 0;
	cin >> N >> M >> C;
	int B[M], A[N][M];
	for(int i=0; i<M; i++) cin >> B[i];
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			cin >> A[i][j];
		}
	}
	for(int i=0; i<N; i++){
		int cnt = 0;
		for(int j=0; j<M; j++){
			cnt += A[i][j] * B[j];
		}
		cnt += C;
		if(cnt > 0) index++;
	}
	cout << index << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np

a = input().split(" ")
N = int(a[0])
M = int(a[1])
gate = []
for i in range(M):
    a = input().split(" ")
    gate.append([int(a[0]),int(a[1])])

gate = np.array(gate)

max = gate.max(axis=0)[0]
min = gate.min(axis=0)[1]

if max > min:
    print(0)
elif max == min:
    if max <= N:
        print(1)
    else:
        print(0)
else:
    if N < max:
        print(0)
    elif max <= N and N <= min:
        print(N-max+1)
    else:
        print(min-max+1)

Measured memory_bytes: 30068
#include <cstdint>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int n;
	cin >> n;
	int len = 1;
	int last = -1;
	int current;
	int64_t sum = 0;
	vector<int> as;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		as.push_back(a);
	}

	int cur1 = 0;
	int cur2 = 0;
	int regionsum = 0;
	while (true) {
		if (regionsum + as[cur2] == (regionsum ^ as[cur2])) {
			regionsum += as[cur2];
			cur2++;
			sum += cur2 - cur1;
			if (cur2 == n) break;
		}
		else {
			regionsum -= as[cur1];
			cur1++;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 1400
package main

import "fmt"

func main() {
	var h, w int

	for {
		fmt.Scan(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		for i := 0; i < h; i++ {
			if i == 0 || i%2 == 0 {
				for j := 0; j < w; j++ {
					if j == 0 || j%2 == 0 {
						fmt.Print("#")
					} else {
						fmt.Print(".")
					}
				}
				fmt.Print("\n")
				
			} else {
				for j := 0; j < w; j++ {
					if j == 0 || j%2 == 0 {
						fmt.Print(".")
					} else {
						fmt.Print("#")
					}
				}
				fmt.Print("\n")
			}
		}
		fmt.Print("\n")
	}
}



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

int c[1001][1001];
char X[1001], Y[1001];

int lcsLength(void) {
  int m, n, i, j;

  m = strlen(X);
  n = strlen(Y);
  for(i = 0; i <= m; i++) {
    c[i][0] = 0;
  }
  for(j = 0; j <= n; j++) {
    c[0][j] = 0;
  }
  for(i = 1; i <= m; i++) {
    for(j = 1; j <= n; j++) {
      if(X[i-1] == Y[j-1]) c[i][j] = c[i-1][j-1] + 1;
      else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }
  return c[m][n];
}

int main() {
  int n, i, x;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s", X);
    scanf("%s", Y);
    x = lcsLength();
    printf("%d\n", x);
  }
  return 0;
}

Measured memory_bytes: 4516
import java.io.*;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] sp1 = line1.split(" ");
		int n = Integer.parseInt(sp1[0]);
		int m = Integer.parseInt(sp1[1]);
		int[][] a = new int[n][m];
		int[] b = new int[m];
		for (int i = 0; i<n  ; i++) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j=0; j<m ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
			}
		}
		for (int i=0 ; i<m ;i++ ) {
			String line = br.readLine();
			b[i] = Integer.parseInt(line);
		}
		int[] c = new int[n];
		for (int i=0 ; i<n ; i++) {
			for (int j = 0; j<m ; j++) {
				c[i] += (a[i][j] * b[j]); 
			}
		}
		for (int youso : c) {
			System.out.println(youso);
		}
	}

}

Measured memory_bytes: 27496
#include<bits/stdc++.h>
using namespace std;
#define ll long
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i = 1; i <= ty - sy; i++) {
		cout << "U";
	}
	for (int i = 1; i <= tx - sx; i++) {
		cout << "R";
	}
	for (int i = 1; i <= ty - sy; i++) {
		cout << "D";
	}
	for (int i = 1; i <= tx - sx; i++) {
		cout << "L";
	}
	cout << "L";
	for (int i = 1; i <= ty - sy + 1; i++) {
		cout << "U";
	}
	for (int i = 1; i <= tx - sx + 1; i++) {
		cout << "R";
	}
	cout << "D";
	cout << "R";
	for (int i = 1; i <= ty - sy + 1; i++) {
		cout << "D";
	}
	for (int i = 1; i <= tx - sx + 1; i++) {
		cout << "L";
	}
	cout << "U";

}

Measured memory_bytes: 3648
//Author:- S_Aditya
//Date created:- 24 February 2019

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=4e2+4;

ll dp[N][N],a[N];

ll rec(int i,int j)
{
    if(i==j)
    return 0;
    
    ll &ans=dp[i][j];
    
    if(ans!=-1)
    return ans;
    
    ans=1e18;
    
    ll sum=0;
    
    for(int k=i;k<=j;k++)
    sum+=a[k];
    
    for(int k=i;k<j;k++)
    {
        //partitioning the segment [i,j] as [i,k] and [k+1,j] and take the contribution
        //answer of dp[i,j] will be dp[i,k]+dp[k+1,j]+sum(i,j)
        //(visualise this process as a building up of a binary tree)
        ll here=rec(i,k)+rec(k+1,j)+sum;
        
        ans=min(ans,here);
    }
    
    return ans;
}

int main()                  
{
    int n;
    
    scn(n);
    
    rep(i,0,n)
    lscn(a[i]);
    
    memset(dp,-1,sizeof(dp));
    
    ll ans=rec(0,n-1);
    
    cout<<ans;
} 


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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 long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
std::vector<std::vector<long long>> comb(int n, int r) {
	std::vector<std::vector<long long>> v(n + 1, std::vector<long long>(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n,h,cnt=0;
	cin >> n >> h;
	vector<ll>a(n), b(n);
	rep(i, n)cin >> a[i] >> b[i];
	sort(all(b));
	reverse(all(b));
	ll maxA = *max_element(all(a));
	for (ll i = 0; i < n; i++) {
		if (b[i] < maxA)break;
		if (h <= 0)return cout << cnt << endl,0;
		h -= b[i];
		cnt++;
	}
	cout << setprecision(15) << cnt + ceil(h / (double)maxA) << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
  int N;
  cin >> N;
  vector<int> C(N), S(N), F(N);
  rep(i, N) {
    cin >> C[i];
    cin >> S[i];
    cin >> F[i];
  }
  rep(i, N) {
    if (i == N - 1) {
      cout << 0 << endl;
      return 0;
    }
    int res = 0;
    int pos = i;
    res += S[i] + C[i];
    pos += 1;
    while (pos < N - 1) {
      if (res < S[pos]) res = S[pos];
      else if (res % F[pos] > 0) res += F[pos] - (res % F[pos]);
      res += C[pos];
      pos++;
    }
    cout << res << endl;
  }
}


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

const int mod = 1e9+7;
long long pot[61] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488};
int sumy[300005][69];

string bin[300005];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	long long a;
	for (int i = 1; i <= n; ++i){
		cin >> a;
		bin[i] = bitset<64>(a).to_string();
		//cout << bin[i] << "\n";
	}
	for (int i = n; i >= 1; i--){
		for (int j = 63; j >= 0; --j){
			sumy[i][j] = sumy[i+1][j] + (bin[i][j] == '1');
		}
	}
	long long wynik = 0;
	for (int i = 1; i <= n; ++i){
		for (int j = 0; j <= 63; ++j){
			if (bin[i][j] == '0'){
				wynik += ((pot[63-j] % mod) * sumy[i+1][j]) % mod;
				wynik %= mod; 
			}
			else{
				int k = n-i-sumy[i+1][j];
				wynik += ((pot[63-j] % mod) * k) % mod;
				wynik %= mod;
			}
		}
	}
	cout << wynik << "\n";
}

Measured memory_bytes: 116224
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(n) for(ll i=0; i<n; i++)
const ll INF = LLONG_MAX;
const ll MOD = 998244353;

ll n, k;
vector<pair<ll, ll> > A;
vector<ll> D;

void change(ll k, ll x)
{
  ll cur = k;
  D[cur] = x;
  cur = (cur-1)/2;
  bool flag = false;
  while(1)
  {
    D[cur] = max(D[2*cur+1], D[2*cur+2]);
    cur = (cur-1)/2;
    if(flag) break;
    if(cur==0) flag = true;
  }
}

void init()
{
  rep(2*k-1) D.emplace_back(-INF);
}

// query to the i-the node whose interval is [l,r)
// what is the value of [a,b)?
ll query_body(ll i, ll a, ll b, ll l, ll r)
{
  if(b <= l || r <= a) return -INF; // I don't know
  if(a <= l && r <= b) return D[i]; // I know
  
  // My children know
  ll c1 = query_body(2*i+1, a, b, l, (l+r)/2);
  ll c2 = query_body(2*i+2, a, b, (l+r)/2, r);
  return max(c1, c2);
}

ll query(ll l, ll r)
{
  return query_body(0, l, r, 0, k);
}

int main()
{
  cin >> n;
  k = 1;
  while(k < n) k *= 2;
  for (ll i = 0; i < n; i++)
  {
    ll x, d;
    cin >> x >> d;
    A.emplace_back(x, d);
  }
  sort(A.begin(), A.end());

  init();

/*
  for(auto p:A)
  {
    cout << p.first << " " << p.second << endl;
  }
*/
  for (ll i = n-1; i >= 0; i--)
  {
    ll x = A[i].first;
    ll d = A[i].second;
    auto itr = lower_bound(A.begin(), A.end(), make_pair(x+d, -INF));
    ll left = i;
    ll right = itr - A.begin();
    ll q = query(left, right);
    if(q < 0) change(k-1+i, i);
    else change(k-1+i, q);
  }

/*
  for(auto d:D) cout << d << " ";
  cout << endl;
*/
  vector<ll> DP(n, -1);
  vector<ll> DP_plus(n, -1);
  
  DP_plus[n-1] = 1;
  DP[n-1] = 2;

  for(ll i = n-2; i >= 0; i--)
  {
    ll j = D[k-1+i];
    if(i==j)
    {
      DP_plus[i] = DP[i+1];
    } else {
      DP_plus[i] = DP_plus[j];
    }
    DP[i] = (DP_plus[i] + DP[i+1]) % MOD;
  }
  cout << DP[0] << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define int long long
signed main(){
//int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    int po=0;
    int ng=0;
    for(int i = 0; i < n; i++) {
        if(a[i]>b[i]) po+=(a[i]-b[i]);
        else ng+=((b[i]-a[i])/2);
    }
    if(ng<po) cout << "No" << "\n";
    else cout << "Yes" << "\n";

    return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 0x3FFFFFFF
using namespace std;
int a[MAXN],w[MAXN],dp[MAXN];
int u,v,val;
int dfs(int s){
	if(s==0)
		return 0;
	if(dp[s])
		return dp[s];
	dp[s]=INF;
	for(int i=1;i<16;i++)
		if(s&(1<<i)){
			for(int j=1;j<16;j++){
				if(j!=i&&(s&(1<<j))){
					int q=i^j;
					if(s&(1<<q))
						dp[s]=min(dp[s],dfs(s^(1<<i)^(1<<j)^(1<<q))+2);
					else
						dp[s]=min(dp[s],dfs(s^(1<<i)^(1<<j)^(1<<q))+1);
				}
			}
			
		}
}
int main(){
	int S,n,ans=0;
	SF("%d",&n);
	for(int i=1;i<n;i++){
		SF("%d%d%d",&u,&v,&val);
		a[u]^=val;
		a[v]^=val;
	}
	for(int i=0;i<n;i++)
		w[a[i]]++;
	for(int i=1;i<16;i++){
		ans+=w[i]/2;
		if(w[i]%2==1)
			S^=(1<<i);
	}
	PF("%d",ans+dfs(S));
}

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

bool is_integer( double x ){
  return std::floor(x)==x;
}

int main(){
    string a, b; cin >> a >> b;
    int x = stoi(a + b);

    cout << (is_integer(sqrt(x)) ? "Yes" : "No") << endl;
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(all(c)); c.erase(unique(all(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

const int MOD = 1'000'000'007;
int D;
string N;

ll dp[10001][2][100][2];

ll solve(int pos = 0, bool tight = true, ll sum = 0, bool all_zero = false)
{
    if (pos == N.size()) {
        return (!all_zero && sum % D == 0) ? 1 : 0;
    }

    int digit = N[pos] - '0';

    ll& rdp = dp[pos][tight ? 1:0][sum][all_zero ? 1:0];
    if (~rdp) return rdp;

    ll res = 0;

    for (int i = 0; i <= (tight ? digit : 9); i++) {
        res += solve(pos + 1, tight && i == digit, (sum + i) % D, i == 0 && (pos == 0 || all_zero));
    }

    return rdp = res % MOD;
}

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

    memset(dp, -1, sizeof dp);

    cin >> N >> D;

    cout << solve() << endl;
}


Measured memory_bytes: 32640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    ll x;
    cin >> x;
    int ans_a, ans_b;
    for(ll i=-1000; i<=1000; i++){
        for(ll j=-1000; j<=1000; j++){
            ll A_5 = i * i * i * i * i;
            ll B_5 = j * j * j * j * j;
            if(A_5 - B_5 == x){
                ans_a = i;
                ans_b = j;
                break;
            }
        }
    }
    cout << ans_a << " " << ans_b;
    return 0;
}

Measured memory_bytes: 3544
using System;

class Program {
    static void Main (string[] args) {
        int[] num = { 1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51 };
        var inp = Console.ReadLine().Split(' ');

        Console.WriteLine(num[Convert.ToInt32(inp[0]) - 1]);
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

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

		int n = sc.nextInt();
		int a[] = new int[n];
		int C = 0;
		int max = 0;

		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			if (b % 2 == 0) a[C++] = b;
		}

		for (int i = 0; i < C; i++) {
			int count = 0;
			while(true) {
				a[i] /= 2;
				count++;
				if (a[i] % 2 == 1) {
					break;
				}
				//System.out.println(a[i]);
			}
			max += count;
		}

		System.out.println(max);
	}
}

Measured memory_bytes: 36148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    vector<string> s(n);
    for(int i = 0;i < n;i++) cin >> s[i];
    
    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            if(s[i] == s[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    for(int i = 0;i < n-1;i++){
        if(s[i].at(s[i].size()-1) != s[i+1].at(0)){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes";
}


Measured memory_bytes: 256
n, h = map(int, input().split())
a_d = []
b_d = []
count = 0
for i in range(n):
  a, b = map(int, input().split())
  a_d.append(a)
  b_d.append(b)
a_max = max(a_d)
b_d = sorted(b_d, reverse=True)

while h > 0 and count <= len(b_d)-1:
  if b_d[count] > a_max:
    h -= b_d[count]
    count += 1
  else:
    break

if h <= 0:
  print(count)
else:
  if h % a_max == 0:
    print(count + h // a_max)
  else:
    print(count + h // a_max + 1)

Measured memory_bytes: 12064