akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int N=1e6;
const int mo=1e9+7;
int Sum(int x,int y) {
    x+=y;
    return (x>=mo)?x-mo:x;
}
int Sub(int x,int y) {
    x-=y;
    return (x<0)?x+mo:x;
}
int Mul(int x,int y) {
    return (long long)x*y%mo;
}
int Pow(int x,int y=mo-2) {
    int z=1;
    while (y) {
        if (y&1) z=Mul(z,x);
        y>>=1;
        x=Mul(x,x);
    }
    return z;
}
int n,vx;
int a[N+10],v[N+10],g[N+10],h1[N+10],h2[N+10],nxt[N+10],lst[N+10];
struct bit {
    int t[N+10];
    void Add(int x,int va) {
        while (x<=N) {
            t[x]=Sum(t[x],va);
            x+=x&(-x);
        }
    }
    int Query(int x) {
        int sum=0;
        while (x) {
            sum=Sum(sum,t[x]);
            x-=x&(-x);
        }
        return sum;
    }
}bit1,bit2,bit3;
int Solve() {
    int ans=0;
    for (int i=1;i<=n;i++) {
        int lx=nxt[a[i]],rx=a[i];
        int sum=Mul(h2[a[i]+1],Sub(bit1.Query(rx),bit1.Query(lx-1)));
        ans=Sum(ans,Mul(sum,(mo+1)/2));
        lx=a[i]+1;
        rx=lst[a[i]+1]-1;
        sum=Mul(h1[a[i]],Sub(bit2.Query(rx),bit2.Query(lx-1)));
        ans=Sum(ans,Sub(Mul(vx,Sub(bit3.Query(n),bit3.Query(lx-1))),Mul(sum,(mo+1)/2)));
        bit1.Add(a[i],h1[a[i]]);
        bit2.Add(a[i],h2[a[i]+1]);
        bit3.Add(a[i],1);
    }
    return ans;
}
int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        v[a[i]]++;
    }
    for (int i=n-1;i>=1;i--) v[i]+=v[i+1]-1;
    vx=1;
    for (int i=1;i<=n;i++)
        vx=Mul(vx,v[i]);
    if (vx==0) {
        printf("0\n");
        return 0;
    }
    int now=1;
    for (int i=1;i<=n;i++) {
        if (v[i]==1) now=i;
        nxt[i]=now;
    }
    now=n+1;
    lst[n+1]=n+1;
    for (int i=n;i>=1;i--) {
        if (v[i]==1) now=i;
        lst[i]=now;
    }
    g[0]=1;
    for (int i=1;i<=n;i++)
        g[i]=Mul(g[i-1],max(v[i]-1,1));
    h1[0]=1;
    for (int i=1;i<=n;i++) h1[i]=Mul(h1[i-1],v[i]);
    h2[n+1]=1;
    for (int i=n;i>=1;i--) h2[i]=Mul(h2[i+1],v[i]);
    for (int i=1;i<=n+1;i++) {
        h1[i]=Mul(h1[i],Pow(g[i]));
        h2[i]=Mul(h2[i],g[i-1]);
    }
    int ans=Solve();
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 27648
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; ++i) {
            h[i] = s.nextInt();
        }
        Arrays.sort(h);
        long sum = 0;
        for (int i = 0; i < n - k; ++i) sum += h[i];
        System.out.println(sum);
    }
}


Measured memory_bytes: 90744
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  for(int i=n;i>0;i--){
    if(t.substr(0,i)==s.substr(n-i,i)){
      cout<<n*2-i;
      return 0;
    }
  }
  cout<<n*2;
}

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

using namespace std;

struct rest{
	string name;
	int score;
	int num;
};

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

	vector<struct rest> v(N);
	for (int i = 0; i < N; i++){
		cin >> v[i].name >> v[i].score;
		v[i].num = i + 1;
	}

	sort(v.begin(), v.end(), 
		[](struct rest& a, struct rest& b){
			if(a.name == b.name){
				if(a.score < b.score){
					return false;
				} else {
					return true;
				}
			} else if(a.name < b.name){
				return true;
			} else {
				return false;
			}
		}
	);

	for (int i = 0; i < N; i++){
		cout << v[i].num << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#define int long long
#define uint unsigned long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

signed main()
{
	int N, C, K;
	cin >> N >> C >> K;
	vector<int> T;
	for (int i = 0; i < N; i++)
	{
		int t;
		cin >> t;
		T.push_back(t);
	}

	sort(T.begin(), T.end());
	T.push_back(-1);

	int time = T[0];
	int c = 0;
	int bus = 0;
	for (int i = 0; i < N; i++)
	{
		if (T[i] > time + K)
		{
			bus++;
			c = 0;
			time = T[i];
		}
		if (T[i] <= time + K)
		{
			c++;
		}
		if (c >= C)
		{
			bus++;
			c = 0;
			time = T[i + 1];
		}
		else if (i == N - 1)
		{
			bus++;
		}
	}

	cout << bus << endl;
}


Measured memory_bytes: 1400
import java.util.*;


import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		long n = nl();
		List<Long> fList = factorization(n);
		long a = fList.get(fList.size() - 1);
		long result = a + n/a - 2;
		System.out.println(result);
	}

	static List<Long> factorization(long a){
		List<Long> result = new ArrayList<>();
		result.add(1L);
		for(int i = 2; i <= Math.sqrt(a) + 1; i++) {
			if(a % i == 0) {
				result.add((long)i);	
			}				
		}
		return result;
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		} 
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23508
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
// stackのパターン
// 実習資料では「srcの訪問時刻は0」となっているが、題意は1である。

#include <iostream>
#include <cstdio>
#include <stack> // 入れたものから出していく引っ越しトラック型の構造。
using namespace std;

int G[110][110];
int n;
int u, k, v;

void make_matrix() {
  fill(&G[0][0], &G[0][0]+110*110, 0);
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d%d", &u, &k);
    u--;
    for (int j=0; j<k; j++) {
      scanf("%d", &v);
      v--;
      G[u][v] = 1;
    }
  }
}

int timer; // timeだとエラーが出たので。
int d[110]; // 訪問時刻。ナマの数字を入れる(indexを-1処理しない)。
int f[110]; // 終了時刻。ナマの数字を入れる。
int parent[110]; // 訪問する原因となった数字を入れる。ナマの数字を入れる。

void init() {
  timer = 1;
  fill(d, d+110, -1);
  fill(f, f+110, -1);
  fill(parent, parent+110, -1);
}

void dfs(int src) {
  // cerr << "dfs root is " << src << endl;
  stack<int> S; // todo訪問先
  S.push(src);
  while (! S.empty()) {
    int cur = S.top(); // 一番最近入れた数字を訪問しようとする。
    S.pop();
    if (d[cur] != -1) { // 過去訪問した場合は、訪問しない。
      continue;
    }
    d[cur] = timer;
    timer++;
    // cerr << "visiting " << cur << " at the time " << d[cur] << endl;
    for (int i=n; i>=1; i--) { // 節点i。逆順に入れていくことに注意！
      if (G[cur-1][i-1] == 1 && d[i] == -1) {
	S.push(i);
	// cerr << "pushing " << i << endl; 
	parent[i] = cur;
        // cerr << "parent[" << i << "] is " << cur << endl;
      }
    }
    int hantei = cur;
    int modoru = -1;
    while (! S.empty() && d[S.top()] != -1) {
      S.pop();
    }
    if (! S.empty()) {
      modoru = parent[S.top()];
    }
    while (hantei != modoru) {
      // cerr << "hantei " << hantei << " modoru " << modoru << endl; 
      f[hantei] = timer;
      timer++;
      hantei = parent[hantei];
      // cerr << "hantei " << hantei << endl;
    }
  }
}

int main() {
  make_matrix();
  init();
  for (int i=1; i<=n; i++) { // 1から連結していない連結成分にも番号をふる。
    if (d[i] == -1) {
      dfs(i);
    }
  }
  for (int i=1; i<=n; i++) {
    printf("%d %d %d\n", i, d[i], f[i]);
  }
}

Measured memory_bytes: 1224
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNext()){
			int n=sc.nextInt();
			if(n==0)break;
			P[] ps=new P[n];
			for(int i=0;i<n;i++){
				String[] str=sc.next().split(",");
				ps[i]=new P(Double.parseDouble(str[0]),Double.parseDouble(str[1]));
			}
			Arrays.sort(ps);
			int k=0;
			P[] qs =new P[2*n];
			//下側
			for(int i=0;i<n;i++){
				while(k>1 && P.cross(qs[k-1].s(qs[k-2]),ps[i].s(qs[k-1]))<=0)k--;//凸包になるまで戻す
				qs[k++]=ps[i];
			}
			//上側
			for(int i=n-2,t=k;i>=0;i--){
				while(k>t && P.cross(qs[k-1].s(qs[k-2]),ps[i].s(qs[k-1]))<=0)k--;
				qs[k++]=ps[i];
			}
			qs=Arrays.copyOf(qs,k-1);

			ln(ps.length-qs.length);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
	public static void pr(Object o) {
		System.out.print(o);
	}
	public static void ln(Object o) {
		System.out.println(o);
	}
	public static void ln() {
		System.out.println();
	}
}

class P implements Comparable<P>{
	double x,y;
	P(double _x,double _y){
		x=_x;
		y=_y;
	}
	@Override
	public int compareTo(P o) {
		if(x>o.x){
			return 1;
		}else if(x<o.x){
			return -1;
		}
		return y>o.y?1:y<o.y?-1:0;
	}
	public static  double cross(P a,P b){
		return a.x*b.y-a.y*b.x;
	}
	public P s(P a){
		return new P(x-a.x,y-a.y);
	}
	public String toString(){
		return "("+x+","+y+")";
	}
}

Measured memory_bytes: 11000
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include <typeinfo>
#include <stdlib.h>
#define ll long long
const int MOD = 1000000007;
using namespace std;

int main() {
	int n, a[50][(int)'z' + 1] = {};
	string s[50], al = "abcdefghijklmnopqrstuvwxyz";
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < s[i].length(); j++) {
			a[i][(int)s[i][j]]++;
		}
	}
	for (int i = 0; i < n - 1; i++) {
		for (int j = (int)'a'; j <= (int)'z'; j++) {
			a[0][j] = min(a[0][j],min(a[i][j], a[i + 1][j]));
		}
	}
	for (int i = (int)'a'; i <= (int)'z'; i++) {
		for (int j = 0; j < a[0][i]; j++) {
			cout << al[i - (int)'a'];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def generate(p):
    n = len(p)
    a = [n*i+1 for i in xrange(n)]
    b = a[::-1]
    for i in xrange(n):
        a[p[i]-1] += i
    return a, b

def main():
    n = int(raw_input().strip())
    p = [int(x) for x in raw_input().strip().split()]
    a, b = generate(p)
    print ' '.join([str(x) for x in a])
    print ' '.join([str(x) for x in b])

if __name__ == '__main__':
    main()

Measured memory_bytes: 5964
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  double t, x;
  cin >> t >> x;
  printf("%.10lf\n", t / x);


  return 0;
}



Measured memory_bytes: 256
N,K = map(int,input().split())
note = [list(map(int,input().split())) for i in range(N)]
note = sorted(note,key=lambda x:(x[0],-x[1]))
cnt = 0
head = []
remain = []
for i in range(N):
    if note[i][0] > cnt:
        cnt = note[i][0]
        head.append(note[i][1])
    else:
        remain.append(note[i][1])
head = sorted(head,reverse = True)
remain = sorted(remain,reverse = True)
ans = 0
acc_head = [0]
acc_remain = [0]
tmp_head = 0
tmp_remain = 0
for i in range(len(head)):
    tmp_head += head[i]
    acc_head.append(tmp_head)
for i in range(len(remain)):
    tmp_remain += remain[i]
    acc_remain.append(tmp_remain)
for i in range(max(0,K-len(remain)),min(K,len(head))+1):
    deli = acc_head[i] + acc_remain[K-i]
    kind = i**2
    res = deli + kind
    if res > ans:
        ans = res
print(ans)

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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with \"n\" of \"nCk\" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

int main() {
	int n;
    cin >> n;
    vector<ll> a(n);
    vector<mint> ps(n+1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ps[i+1] = mint(a[i]) + ps[i];
    }

    mint ans;
    for (int i = 0; i+1 < n; ++i) {
        mint sum = ps[n] - ps[i+1];
        ans += sum * mint(a[i]);
    }
    cout << ans.x << endl;
}


Measured memory_bytes: 6420
x, n = map(int, input().split())
p = list(map(int, input().split()))
num = [i for i in range(1, 101) if i not in p]
l = 0
r = 101
for i in num:
    if i <= x:
        l = max(l, i)
    else:
        r = min(r, i)
# print(l, r)
if l+r == 2*x:
    ans = l
elif x-l < r-x:
    ans = l
else:
    ans = r

print(ans)

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

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> h;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		h.push_back(x);
	}

	vector<int> cost(n,0);
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			cost[i]=0;
		}
		else if(i<=k)
		{
			cost[i]=INT_MAX;
			for(int j=0;j<i;j++)
			{
				cost[i]= min(cost[j]+abs(h[i]-h[j]) , cost[i]);
			}
		}
		else
		{
			cost[i]=INT_MAX;
			for(int j=i-k;j<i;j++)
			{
				cost[i]= min(cost[j]+abs(h[i]-h[j]) , cost[i]);
			}
		}
		//cout<<cost[i]<<" ";
	}
	cout<<cost[n-1];
	return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int k, a, b;
		cin >> k >> a >> b;

		int x = a/k, y = b/k;

		if(a%k==0 || b%k==0 || abs(y-x)>=1)
			cout << "OK";
		else
			cout << "NG";
	}
	return 0;
}

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

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


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int p[600*600];
int d[600][600];
bool b[600][600];

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

int main(){
	int n;cin>>n;
	rep(i,n*n)scanf("%d",&p[i]),p[i]--;
	rep(i,n)rep(j,n){
		d[i][j]=min({i,j,n-i-1,n-j-1});
		b[i][j]=true;
	}
	ll ans=0;
	rep(i,n*n){
		int x=p[i]/n,y=p[i]%n;
		ans+=d[x][y];
		//~ if(d[x][y]){
			//~ cout<<"-----"<<i<<' '<<p[i]<<endl;
			//~ rep(i,n){
				//~ rep(j,n)cout<<b[i][j]<<' ';
				//~ cout<<endl;
			//~ }
		//~ }
		b[x][y]=false;
		deque<P>que;
		que.push_back(P(x,y));
		while(!que.empty()){
			P p=que.front();que.pop_front();
			rep(k,4){
				int nx=p.first+dx[k],ny=p.second+dy[k];
				if(0<=nx&&nx<n&&0<=ny&&ny<n){
					int c=d[p.first][p.second]+b[p.first][p.second];
					if(d[nx][ny]>c){
						d[nx][ny]=c;
						if(b[p.first][p.second])que.push_back(P(nx,ny));
						else que.push_front(P(nx,ny));
					}
				}
			}
		}
		//~ puts("");
	}
	cout<<ans<<endl;
}

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

long long int gcd(long long int a, long long int b) {
  if(b == 0)return a;
  return gcd(b, a % b);
}

int main(){
  int n;cin>>n;
  long long int a[n];
  for(int i=0;i<n;++i){
    cin>>a[i];
  }
  long long int ans=1;
  for(int i=0;i<n;++i){
    ans*=a[i]/gcd(ans,a[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
*A1, = map(int, input().split())
*A2, = map(int, input().split())
*A3, = map(int, input().split())
A = A1 + A2 + A3
N = int(input())
a = [int(input()) for _ in range(N)]
chk = [A[:3], A[3:6], A[6:9], A[::3], A[1::3], A[2::3], A[::4], A[2:7:2]]
for c in chk:
    ans = 0
    for cc in c:
        if cc in a:
            ans += 1
    if ans == 3:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,B[100],sum;
	cin>>N;
	for(int i=0;i<N-1;i++)cin>>B[i];
	sum=B[0];
	for(int i=0;i<N-2;i++){
		sum+=min(B[i],B[i+1]);
	}
	sum+=B[N-2];
	cout<<sum;
	return 0;
}

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

#define ff first
#define endl "\n"
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fr(i,x,n) for(ll i=x;i>=n;i--)
inline ll min(ll a, ll b, ll c) { return min(min(a, b), c);}
inline ll max(ll a, ll b, ll c) { return max(max(a, b), c);}
inline void fastio(){ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);}

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

ll func(ll x){
	if(x==1) return 1;
	return 2*func(x/2)+1;
}

int main(){
	fastio();

	ll h; cin>>h;
	cout<<func(h);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }


ll choose(ll n, ll r){
    ll res = 1;
    for(int i = 1; i <= r; i++){
        res *= n--;
        res /= i;
    }
    return res;
}

int main(){
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int e = 0, o = 0;
    rep(i,n) {
        if (a[i] % 2 == 0) e++;
        else o++;
    }
    ll eNum = 0, oNum = 0, ans;
    if (p == 0){
        if (e == 0){
            for(int i = 0; i <= o; i += 2){
                oNum += choose(o, i);
            }
            ans = oNum;
        }else if (o == 0){
            eNum = 1LL << e;
            ans = eNum;
        }else{
            eNum = 1LL << e;
            for(int i = 0; i <= o; i += 2){
                oNum += choose(o, i);
            }
            ans = eNum * oNum;
        }
    }else{
        if (e == 0){
            for(int i = 1; i <= o; i += 2){
                oNum += choose(o, i);
            }
            ans = oNum;
        }else if (o == 0){
            ans = 0;
        }else{
            eNum = 1LL << e;
            for(int i = 1; i <= o; i += 2){
                oNum += choose(o, i);
            }
            ans = eNum * oNum;
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int h,w;
  while(cin>>h>>w,h+w) {
    char ba[w][h];
    REP(y,h) {
      REP(x,w) {
        cin >> ba[x][y];
      }
    }
    int x = 0, y = 0;
    int dx[] = {0,1,0,-1};
    int dy[] = {-1,0,1,0};
    char aa[] = {'^','>','v','<'};
    map<char,int> hoge;
    REP(i,4)
      hoge[aa[i]] = i;
    int f[w][h];
    memset(f,0,sizeof(f));
    while(true) {
     
      if (f[x][y]) break;
      if (ba[x][y] == '.') break;

      f[x][y]=1;
      int aa = hoge[ba[x][y]];
      x += dx[aa];
      y += dy[aa];
    }
    if (f[x][y]) cout << "LOOP" << endl;
    else cout << x << " " << y << endl;
  }
}

Measured memory_bytes: 0
class Queue(object):
    def __init__(self, _max):
        if type(_max) != int:
            raise ValueError
        self._array = [None for i in range(0, _max)]
        self._head = 0
        self._tail = 0
        self._cnt = 0

    def enqueue(self, value):
        if self.is_full():
            raise IndexError
        self._array[self._head] = value
        self._cnt += 1
        if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

    def dequeue(self):
        if self.is_empty():
            raise IndexError
        value = self._array[self._tail]
        self._cnt -= 1
        if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
        return value

    def is_empty(self):
        return self._cnt <= 0

    def is_full(self):
        return self._cnt >= len(self._array)


def round_robin(quantum, jobs):
    queue = Queue(len(jobs))
    total = 0
    for job in jobs:
        queue.enqueue(job)

    while not queue.is_empty():
        name, time = queue.dequeue()
        if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total))


if __name__ == "__main__":
    n, quantum = input().split()
    jobs = [input().split() for i in range(0, int(n))]
    jobs = [(job[0], int(job[1])) for job in jobs]
    round_robin(int(quantum), jobs)

Measured memory_bytes: 24432
#include<iostream>
#include<string>
#include<stdbool.h>
using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a == b)cout << "Draw" << endl;
	else {
		if (a == 1) {
			cout << "Alice" << endl;
		}
		else {
			if (b == 1)cout << "Bob" << endl;
			else {
				if (a > b)cout << "Alice" << endl;
				else cout << "Bob" << endl;
			}
		}
	}
	return 0;
}

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

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

using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	int i,ans=0,sum=0;
	vector<int> result(N);
	FOR(i,1, N) {
		if (S[i] == 'E') {
			result[i] = result[i - 1] - 1;
			++sum;
		}
		else
			result[i] = result[i - 1];
		result[i] = S[i - 1] == 'W' ? result[i] + 1 : result[i];
		ans = result[ans] > result[i] ? i : ans;
	}
	cout << sum + result[ans] << endl;
}

Measured memory_bytes: 1796
let N = stdin.ReadLine() |> int64

let A =
    stdin.ReadLine().Split()
    |> Array.map int64
    |> Array.sortDescending

let rec solver s i =
    if i = N - 1L then s
    else solver (s + A.[int ((i + 1L) / 2L)]) (i + 1L)

solver 0L 0L |> stdout.WriteLine


Measured memory_bytes: 48872
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
max_a = max(a for a, _ in ab)
dp = [0]*(H+max_a)
for i in range(1,H+1):
  dp[i] = min(dp[i-a]+b for a,b in ab)
print(dp[H])



Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ll n, k;
  cin >> n >> k;

  cout << min(n % k, k - n % k) << endl;


  
  return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >>N;
	for(int i=0;i<N;i++){
		string s1,s2;
		cin >>s1;
		cin >>s2;
		
		if(s1.size()<s2.size()){
			string tmp = s1;
			s1 = s2;
			s2 = tmp;
		}
		
		if(s1.size()>80){
			cout <<"overflow" <<endl;
			continue;
		}
		
		int A[80];
		int C = 0;
		for(int j=0;j<s1.size();j++){
			int tmp = (int) (s1[s1.size()-1-j] - '0') + C;
			if(j<s2.size()){
				tmp += (int) (s2[s2.size()-1-j] - '0');
			}
			A[j] = tmp % 10;
			C = tmp/10;
		}
		if(s1.size()==80&&C==1){
			cout <<"overflow" <<endl;
		}else{
			if(C==1){
				cout <<C;
			}
			for(int j=s1.size()-1;j>=0;j--){
				cout <<A[j];
			}
			cout <<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
long long n,m,a[333][333],pw[666],cnt,pos,cur,upper;
long long Guass(long long Row,long long Column)
{
    long long row=1,col=1,max_r;
    for(row=1;row<=Row&&col<=Column;row++,col++)
    { 
        max_r=row;
        for(long long i=row+1;i<=Row;i++)
            if(abs(a[i][col])>abs(a[max_r][col]))
                max_r=i;
        if(a[max_r][col]==0)
        {
            row--;
            continue;
        }
        if(max_r!=row)
            for(long long i=col;i<=Column;i++)
                swap(a[row][i],a[max_r][i]);

        for(long long i=row+1;i<=Row;i++)
        {
            if(a[i][col]!=0)
            {

                for(long long j=col;j<=Column;j++)
                    a[i][j]^=a[row][j];
            }
        }
    }
	return Column-row+1;
}
/*void gauss()
{
	upper=1;
	for (long long i=1;i<=m;i++)
	{
		pos=-1;
		for (long long j=upper;j<=n;j++)
		{
			if (a[j][i])
			{
				pos=j;
				break;
			}
		}
		if (~pos)
		{
			cnt++;
			for (long long j=1;j<=m;j++) swap(a[i][j],a[pos][j]);
			for (long long j=upper+1;j<=n;j++)
			{
				if (a[j][i])
				{
					for (long long k=i;k<=m;k++)
					{
						a[j][k]^=a[upper][k];
					}
				}
			}
			upper++;
		}
	}
} */ 
int main()
{
	scanf("%lld%lld",&n,&m);
	for (long long i=1;i<=n;i++)
	{
		for (long long j=1;j<=m;j++)
		{
			scanf("%lld",&a[i][j]);
		}
	}
	pw[0]=1;
	for (long long i=1;i<=600;i++) pw[i]=pw[i-1]*2%mod;
	cur=pw[Guass(n,m)];
	printf("%lld\n",((pw[n+m-1]-pw[n-1]*cur)%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
 int main(void)
 {
     int N,D,X,A[105];
     int i,j,k=0;

     scanf("%d",&N); // menber
     scanf("%d%d",&D,&X); // days rest

     for(i=0;i<N;i++)
       scanf("%d",&A[i]); // number

     for(i=0;i<N;i++){
       for(j=1;j<100;j++){
         if(j*A[i]+1<=D) k++;
         else break;
       }
     }

     printf("%d\n",k+N+X);

     return 0;
 }



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const double EPS = 1e-9;
template<class T> int GaussJordan(vector<vector<T>> &A, bool is_extended = false) {
    int m = A.size(), n = A[0].size();
    int rank = 0;
    for (int col = 0; col < n; ++col) {
        // 拡大係数行列の場合は最後の列は掃き出ししない
        if (is_extended && col == n-1) break;

        // ピボットを探す
        int pivot = -1;
        T ma = EPS;
        for (int row = rank; row < m; ++row) {
            if (abs(A[row][col]) > ma) {
                ma = abs(A[row][col]);
                pivot = row;
            }
        }
        // ピボットがなかったら次の列へ
        if (pivot == -1) continue;

        // まずは行を swap
        swap(A[pivot], A[rank]);

        // ピボットの値を 1 にする
        auto fac = A[rank][col];
        for (int col2 = 0; col2 < n; ++col2) A[rank][col2] /= fac;

        // ピボットのある列の値がすべて 0 になるように掃き出す
        for (int row = 0; row < m; ++row) {
            if (row != rank && abs(A[row][col]) > EPS) {
                auto fac = A[row][col];
                for (int col2 = 0; col2 < n; ++col2) {
                    A[row][col2] ^= A[rank][col2] * fac;
                }
            }
        }
        ++rank;
    }
    return rank;
}

template<class T> vector<T> linear_equation(vector<vector<T>> A, vector<T> b) {
    // extended
    int m = A.size(), n = A[0].size();
    vector<vector<T>> M(m, vector<T>(n + 1));
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);
    
    // check if it has no solution
    vector<T> res;
    for (int row = rank; row < m; ++row) if (abs(M[row][n]) > EPS) return res;

    // answer
    res.assign(n, 0);
    for (int i = 0; i < rank; ++i) res[i] = M[i][n];
    return res;
}


void solve(int m,int n,int d){
    vector<int> a(n*m);
    rep(i,n)rep(j,m)cin>>a[m*i+j];
    vector<vector<int>> mat(n*m,vector<int>(n*m));
    rep(x1,n)rep(y1,m){
        mat[x1*m+y1][x1*m+y1]=1;
        rep(x2,n)rep(y2,m){
            if(abs(x1-x2)+abs(y1-y2)==d){
                mat[x1*m+y1][x2*m+y2]=1;
            }
        }
    }
    vector<int> res = linear_equation(mat,a);
    if(!res.empty())cout<<1<<endl;
    else cout<<0<<endl;

}
int main(){
    int n,m,d;
    while(cin>>n>>m>>d,n)solve(n,m,d);
    return 0;
}


Measured memory_bytes: 7548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    string s;cin>>s;
    if(s[0]!='A'){co("WA");return 0;}
    int ccnt=0;
    for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C')ccnt++;
    }
    if(ccnt!=1){co("WA");return 0;}
    int ucnt=0;
    rep(i,s.size()){
        if(isupper(s[i]))ucnt++;
    }
    if(ucnt!=2){co("WA");return 0;}
    co("AC");
}

Measured memory_bytes: 256
#include <stdio.h>

void output(int a[],int n){
    int i;
    for(i=0;i<n;i++){
        if(i==0)printf("%d",a[i]);
        else printf(" %d",a[i]);
    }
    printf("\n");
    return;    
}

int main(void){
    int i,j;
    
    int n;
    scanf("%d\n",&n);
    
    int a[n],x;
    scanf("%d",&a[0]);
    for(i=1,j=1;i<n;i++){
        scanf("%d",&x);
        if(a[j-1]!=x)a[j++]=x;
    }
    
    output(a,j);
    
    return 0;
}



Measured memory_bytes: 2188
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
const int Nx = 1e6 + 1;
bool isPrime[Nx+1];
void sieveFindPrime() {
	for(int i = 2; i <= Nx;++i) {
		isPrime[i] = true;
		if(i%2==0){
			if(i != 2){
				isPrime[i] = false;
			}
		}
	}
	isPrime[0] = false;
	isPrime[1] = false;
	for(int i = 3; i * i <= Nx; i+=2) {
		if(isPrime[i] == true) {
			for(int j = i * i; j <= Nx ;j += i)
				isPrime[j] = false;
		}
	}
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	sieveFindPrime();
	cin>>n;
	for(int i=n;;i++){
		if(isPrime[i]){
			cout<<i<<"\n";
			return 0;
		}
	}
    return 0;
}
//.........

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int A[200000];
int main(){
  int N;
  cin >> N;
  set <int> set_A;
  set <int> multi_count;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(set_A.find(A[i]) != set_A.end()){
      multi_count.insert(A[i]);
    }
    set_A.insert(A[i]);
  }

  if(multi_count.find(1) != multi_count.end()){
    cout << 0 << endl;
    return 0;
  }
  if(set_A.find(1) != set_A.end()){
    cout << 1 << endl;
    return 0;
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    bool is_ans = true;
    if(multi_count.find(A[i]) != multi_count.end()){
      continue;
    }
    for(int j = 2; j < sqrt(A[i]) + 1; j++){
      if(A[i] % j == 0){
        if(j == 1){
          if(set_A.find(j) != set_A.end()){
            is_ans = false;
            break;
          }
        } else {
          if(set_A.find(j) != set_A.end() || set_A.find(A[i] / j) != set_A.end()){
            is_ans = false;
            break;
          }
        }
      }
    }
    if(is_ans || A[i] == 2){
      ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13776
x, n = [int(i) for i in input().split()]
ps = [int(i) for i in input().split()]

tmp = [(abs(i-x), i) for i in range(0, 102) if i not in ps]
min_d = min(tmp, key=lambda x: x[0])[0]

ans = min(filter(lambda x: x[0] == min_d, tmp), key=lambda x:x[1])

print(ans[1])


Measured memory_bytes: 9196
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define pb push_back

int main(int argc, char** argv) {
	ll a,b,n;
	cin>>a>>b>>n;
	ll l=min(b-1,n);
	
	cout<<((a*l)/b)-a*(l/b);
	return 0;
}



Measured memory_bytes: 3624
N, M = map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if M == 0 and N == 0:
    print(0)
elif M == 1 and N == 1:
    print(0)
elif M <= 1:
    print(cmb(N, 2))
elif N <= 1:
    print(cmb(M, 2))
else:
    a = cmb(M, 2)
    b = cmb(N, 2)
    print(a + b)

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {

    int N;

    cin >> N;

    vector<int> v;

    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        v.push_back(d);
    }

    sort(v.rbegin(), v.rend());

    int count = 1;

    int current = v[0];

    for (int i = 1; i < N; i++) {

        if (current != v[i]) {
            current = v[i];
            count += 1;
        }
    }

    cout << count << "\n";


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		if(n==1){
			n=0;
        }
		else if(n==0){
			n=1;
        }
		System.out.println(n);
	}
}

Measured memory_bytes: 35656
def check(ary)
  [ary,ary.transpose].each do |a|
    a.each do |a,b,c|
      return true if a && b && c
    end
  end
  if ary[1][1]
    return true if ary[0][0] && ary[2][2] || ary[0][2] && ary[2][0]
  end
  false
end

ary = []
3.times { ary << gets.split.map(&:to_i) }
result = Array.new(3){[false]*3}
gets.to_i.times do
  n = gets.to_i
  ary.each_with_index do |l,i|
    l.each_with_index do |m,j|
      result[i][j] = true if m == n
    end
  end
end
puts check(result) ? "Yes" : "No"

Measured memory_bytes: 14288
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b;
    cin >> a >> b;
    if (a * b % 2 == 0) {
      cout << "Even" << endl;
    } else {
      cout << "Odd" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n=int(input())
L = []
for i in range(n):
  a = input()
  a = sorted(a)
  L.append(a)
L = sorted(L)


k=1
sum=0
for i in range(n-1):
  if L[i]==L[i+1]:
    k += 1
  else:
    if k!=1:
      sum += cmb(k,2)
    k=1
if k!=1:
  sum += cmb(k,2)
print(sum)



Measured memory_bytes: 26044
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlt():
    return(list(map(int, input().split())))


n = inp()

arr = inlt()

arr = sorted(arr)
a = 0
b = 0
for i in range(n):
    if i % 2 == 0:
        a += arr[i]
    else:
        b += arr[i]
print(abs(a-b))


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
    long long int x, t = 1, conta = 100;
    scanf("%lld", &x);
    
    for (;;) {
        conta += conta / 100;
        
        if (conta >= x) {
            printf("%lld", t);
            break;
        } else
            ++t;
    }
    
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define LL long long
using namespace std;

#define int int
inline int Max(int a,int b) {return a>b?a:b;}
inline int Min(int a,int b) {return a<b?a:b;}
inline int Sqr(int a) {return a*a;}
inline int Abs(int a) {return a>0?a:-a;}
#undef int

LL a,b,ans,mi=1ll<<61;

void Solve(int v) {
	if(!(~v)) return;
	if(b>>v&1&&!(a>>v&1)) {
		ans+=min((1ll<<v)-1,mi>>v&1 ? mi^(1ll<<v):mi)-max(a-1,b^(1ll<<v));
		mi=max(a-1,b^(1ll<<v));
		a=0;b=b^(1ll<<v);
	}
	if((b>>v&1)&&(a>>v&1)) {
		b^=1ll<<v;a^=1ll<<v;
	}
	Solve(v-1);
}

int main() {
	cin>>a>>b;
	ans=b-a+1;
	Solve(60);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>
#include <math.h>

using namespace std;

int main(){
    string s;
    cin>>s;
    int i=0;
    int t=0;
    while(s[i]!='\0'){
        if(t==0 && s[i]=='A'){
            t++;
        }
        if(t==1 && s[i]=='C' && s[i-1]=='A'){
            cout<<"Yes"<<endl;
            return 0;
        }
        i++;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int n,k;
    cin >> n >> k;
    vector<ll> v1(n+1);
    ll ans=0;
    v1[0]=0;
    REP(i,n+1){
        if(i==0)continue;
        v1[i]=v1[i-1]+i;
    }
    vector<ll> v2(n+1);
    v2[0]=n;
    IREP(i,n+1){
        if(i==n)continue;
        v2[n-i]=v2[n-i-1]+i;
    }
    for(int i=k;i<=n+1;i++){
        ans += v2[i-1]-v1[i-1]+1;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6428
#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
i64 gcd(i64 x,i64 y){
	return y?gcd(y,x%y):x;
}
bool chk(){
	i64 A,B,C,D;
	cin >> A >> B >> C >> D;
	if(D<B || A<B)return false;
	if(C>=B-1)return true;
	i64 g=gcd(B,D);
	A%=g;
	return B-g+A <= C;
}
int main(){
	int _;
	for(cin >> _; _--;){
		cout << (chk()? "Yes" :"No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,m,gakusei[51][3],point[51][3],s,t=200000001,num,i,j;

	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		for(j=0;j<2;j++)
			scanf("%d",&gakusei[i][j]);
	for(i=0;i<m;i++)
		for(j=0;j<2;j++)
			scanf("%d",&point[i][j]);

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			s=abs(gakusei[i][0]-point[j][0])+abs(gakusei[i][1]-point[j][1]);
			if(t>s){
				t=s;
				num=j;
			}
		}
		printf("%d\n",num+1);
		t=200000001;
	}
	return 0;
}


Measured memory_bytes: 1680
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N) {
    return N * (N - 1) / 2;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N);
    else
        solve(N).writeln;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
int k;
bool flag = 0,qwq = 0;
int sum = 0;
int arr[1007];
void dfs(int p,int s,int b)
{
	if(flag) return;
	if(p == 1){
			if(b) for(int i = max(0,s-1);i <= min(9,s+1);i ++){
				sum ++;
				arr[p] = i;
				if(sum == k){
					flag = 1;return;
				}
			}
			else {
				for(int i = 1;i <= 9;i ++){
					sum ++;
					arr[p] = i;
					if(sum == k){
						flag = 1;return;
					}
				}
			}
		
	}
	else{
		if(b) for(int i = max(0,s-1);i <= min(9,s+1);i ++){
			arr[p] = i;
			dfs(p-1,i,b);
			if(flag) return;
		}
		else{
			for(int i = 0;i <= 9;i ++){
			arr[p] = i;
			if(i == 0) dfs(p-1,i,b);
			else dfs(p-1,i,1);
			if(flag) return;
		}
		}
	}
}

void print()
{
	int i = 100;
	while(arr[i] == 0) i--;
	for(;i >= 1;i --) printf("%d",arr[i]);
}

int main()
{

	scanf("%d",&k);
	dfs(100,0,0);
	print();
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
vector<pair<int,int>> g[MAX_N];

ll dist[MAX_N];

void dfs(int u, int prev, ll cur_dist) {
  dist[u] = cur_dist;
  for (auto e : g[u]) if (e.first != prev) {
    dfs(e.first, u, cur_dist + e.second);
  }
}
int main2() {
  REP(i, MAX_N) g[i].clear();
  int N = nextLong();

  REP(i, N-1) {
    int a = nextLong() - 1;
    int b = nextLong() - 1;
    ll c = nextLong();
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }

  int Q = nextLong();
  int K = nextLong() - 1;
  dfs(K, -1, 0);
  REP(_, Q) {
    int x = nextLong() - 1;
    int y = nextLong() - 1;
    ll ans = dist[x] + dist[y];
    cout << ans << '\n';
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 17216
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define MOD 1000000007
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
	int w, h;
	scanf("%d %d", &w, &h);
	vector<int> p(w), q(h);
	vector<ll> ps(w+2);

	ll ans = 0;
	REP(i, w) {
		scanf("%d", &p[i]);
		ans += p[i];
	}
	REP(i, h) {
		scanf("%d", &q[i]);
		ans += q[i];
	}
	
	sort(p.begin(), p.end());
	REP(i, w) {
		ps[i+1] += (ll)p[i];
		ps[i + 2] += ps[i+1];
	}
	
	REP(i, h) {
		auto itr = upper_bound(p.begin(), p.end(), q[i]);
		int dis = p.end() - itr;
		ans += (ll)dis*q[i];
		ans += ps[w-dis];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
div = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))
count = 0
ans = 0

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            ans += (i < j)
            count += 1

ans *= K
ans += count * (K - 1) * K // 2
ans %= div

print(ans)

Measured memory_bytes: 3188
A, B, C, X, Y = list(map(int, input().split()))

ans = 0
numab = min(X, Y)
if C * 2 < A + B:
    ans += numab * C * 2
else:
    ans += numab * (A + B)

if X < Y:
    if C * 2 < B:
        ans += (Y - X) * C * 2
    else:
        ans += (Y - X) * B
else:
    if C * 2 < A:
        ans += (Y - X) * C * 2
    else:
        ans += (X - Y) * A

print(ans)


Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main(void)
{
    int A, B;
 
    cin >> A >> B;
 
    if(A>=1 && A<=9 && B>=1 && B<=9){
        cout << A*B << endl;
    }
 
    else{
        cout << -1 << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int H = scan.nextInt();
		int M = scan.nextInt();
		double ab = 0;
		double other = 0;
		double longHand = 0;
		double shortHand = 0;
		double angle = 0;
		int min = H * 60 + M;
		
		ab = Math.pow(A, 2) + Math.pow(B, 2);
		
		longHand = 6 * M;
		shortHand = 0.5 * min;
		angle = shortHand - longHand;
		if (H > 6) {
			angle = 360 - angle;
		}
		
		other = (2 * A * B) * Math.cos(Math.toRadians(angle));
		if (angle == 90.0) {
			other = 0;
		}
		
		System.out.println(Math.sqrt(ab - other));
		/*
		System.out.println(ab);
		System.out.println(other);
		System.out.println(Math.cos(Math.toRadians(90.0)));
		System.out.println(angle);
		*/
	}
}

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

int main(){
  int N, sum, a;
  sum = 0;
  cin >> N;
  a = N;
  while(a > 0){
    sum += a % 10;
    a /= 10;
  }
  if(N % sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256