akhauriyash/Code-Regression huggingface dataset:
def main():
    s = str(input())
    n = len(s)
    x, y = map(int, input().split())

    dx = []
    dy = []
    dir = 0
    cnt = 0
    for i in range(n):
        if s[i] == 'F':
            cnt += 1
        else:
            if dir%2 == 0:
                dx.append(cnt)
                cnt = 0
                dir += 1
            else:
                dy.append(cnt)
                cnt = 0
                dir += 1
    else:
        if dir%2 == 0:
            dx.append(cnt)
        else:
            dy.append(cnt)

    dpx = [0]*(len(dx)+1)
    dpy = [0]*(len(dy)+1)

    import numpy as np
    D = 2*n+1
    dpx[0] = np.zeros(D, np.bool)
    dpy[0] = np.zeros(D, np.bool)
    dpx[0][n] = 1
    dpy[0][n] = 1

    for i in range(len(dx)):
        d = dx[i]
        if i == 0:
            b = np.zeros(D, np.bool)
            b[d:] |= dpx[i][:D-d]
        else:
            b = np.zeros(D, np.bool)
            b[d:] |= dpx[i][:D-d]
            b[:D-d] |= dpx[i][d:]
        dpx[i+1] = b

    for i in range(len(dy)):
        d = dy[i]
        b = np.zeros(D, np.bool)
        b[d:] |= dpy[i][:D-d]
        b[:D-d] |= dpy[i][d:]
        dpy[i+1] = b

    if dpx[-1][n+x] and dpy[-1][n+y]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 136696
#include <stdio.h>

int N, A, B, C, i, ans = 0;
int l[8];

int abs(int x) { if( x > 0 ) { return x; } return -x; }

int min3(int a, int b, int c) {
    int ans = a;
    if( ans > b) { ans = b;}
    if( ans > c) { ans = c;}
    return ans;
}

int min4(int a, int b, int c, int d) {
    int ans = a;
    if( ans > b) {ans = b;}
    if( ans > c) {ans = c;}
    if( ans > d) {ans = d;}
    return ans;
}

int dfs(int cur, int a, int b, int c) {
    if(cur == N) {
        if( min3(a, b, c) > 0 ){
            return abs(a-A) + abs(b-B) + abs(c-C) - 30;
        } else {
            return 32767; // int の正の最大数
        }
    }
    int ret0 = dfs(cur + 1, a, b, c);
    int ret1 = dfs(cur + 1, a+l[cur], b, c) + 10;
    int ret2 = dfs(cur + 1, a, b+l[cur], c) + 10;
    int ret3 = dfs(cur + 1, a, b, c+l[cur]) + 10;
    return min4(ret0, ret1, ret2, ret3);
}

int main(void) 
{
    scanf("%d %d %d %d", &N, &A, &B, &C);
    for(i = 0; i < N; ++i){
        scanf("%d", &l[i]);
    }

    printf("%d\n", dfs(0, 0, 0, 0));
    return 0;

}

Measured memory_bytes: 256
class Node:
    def __init__(self, id):
        self.id = id
        self.left = None
        self.right = None
        self.sibling = None
        self.degree = 0
        self.parent = None
        self.depth = -1
        self.nodeType = ''

    def __repr__(self):
        return self.__str__()

    def __str__(self):
        parent_id = self.parent.id if self.parent != None else -1
        sibling_id = self.sibling.id if self.sibling != None else -1
        return 'node ' + str(self.id)\
                + ': parent = ' + str(parent_id)\
                + ', sibling = ' + str(sibling_id)\
                + ', degree = ' + str(self.degree)\
                + ', depth = ' + str(self.depth)\
                + ', height = ' + str(self.high)\
                + ', ' + self.get_node_type()

    def set_depth(self, now_depth):
        self.depth = now_depth
        if self.left != None:
            self.left.set_depth(now_depth + 1)

        if self.right != None:
            self.right.set_depth(now_depth + 1)

    def set_high(self):
        if self.left == None and self.right == None:
            self.high = 0
            return 0
        left_high = 0
        right_high = 0
        if self.left != None:
            left_high = self.left.set_high()
        if self.right != None:
            right_high = self.right.set_high()
        self.high = max([left_high, right_high]) + 1
        return self.high

    def get_node_type(self):
        if self.parent == None:
            return 'root'
        elif self.left == None and self.right == None:
            return 'leaf'
        else:
            return 'internal node'

n = int(raw_input())
tree = [Node(i) for i in xrange(n)]
for i in xrange(n):
    line = map(int, raw_input().split())
    id, left_id, right_id = line[0], line[1], line[2]
    if left_id != -1:
        tree[id].left = tree[left_id]
        tree[left_id].parent = tree[id]
        tree[id].degree += 1
    if right_id != -1:
        tree[id].right = tree[right_id]
        tree[right_id].parent = tree[id]
        tree[id].degree += 1
    if left_id != -1 and right_id != -1:
        tree[left_id].sibling = tree[right_id]
        tree[right_id].sibling = tree[left_id]

# find root
root = None
for t in tree:
    if t.parent == None:
        root = t

root.set_depth(0)
root.set_high()

for t in tree:
    print t

Measured memory_bytes: 6548
#include <stdio.h>

int main(int argc, char const *argv[]) {

    int counter[26] = {};
    char ch;
    
    while (scanf("%c", &ch) != EOF) {   
        if ('a' <= ch && ch <= 'z') {
            counter[ch - 'a']++;
        } else if ('A' <= ch && ch <= 'Z') {
            counter[ch - 'A']++;
        }
    }

    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", 'a' + i, counter[i]);
    }

    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- ]
void Calc(){
	int N = rei();
	int A = rei();
	int B = rei();
	int a = 0;
	int b = 0;
	int c = 0;
	for(int i=0;i<N;i++){
		int x = rei();
		if(x <= A){
			a++;
		}
		else if(x <= B){
			b++;
		}
		else{
			c++;
		}
	}
	cout << min(a,min(b,c)) << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
import math

N, K = map(int, input().split())

expNum = math.ceil(math.log(K, 2))
# print(expNum)
possibility_arr = []

for i in range(N):
    num = i + 1
    if num < K:
        tempNum = K/num
        expNum = math.ceil(math.log(tempNum, 2))
        poss = 1/N * 1/2**expNum
    else:
        poss = 1/N
    #print(poss)
    possibility_arr.append(poss)

# print(possibility_arr)

print(sum(possibility_arr))


Measured memory_bytes: 44912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, T, A;
int H[1010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> T >> A;
  int pos = -1;
  double mn = 1e9;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
    double tmp = T - H[i] * 0.006;
    if (pos < 0 || abs(A-tmp) < mn) {
      mn = abs(A-tmp);
      pos = i;
    }
  }
  cout << pos+1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
int main()
{
    ll m=0,n,c=0,x,t;
    cin>>n;
    ll a[n+10];
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }

    for(int i = 0; i < n-1; i++)
    {
        if(a[i] > a[i+1])
        {
            c += a[i]-a[i+1];
            a[i+1] = a[i];
        }
    }

    cout<<c<<endl;

}


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

using namespace std;

const int MAX_N = 123, MAX_W = 123456;
long long n, capacity, v[MAX_N], w[MAX_N], dp[MAX_W];

int main() {

    cin >> n >> capacity;

    for (int i = 0; i < n; ++i)
        cin >> w[i] >> v[i];

    for (int i = 0; i <= capacity; ++i) {
        dp[i] = -1;

        if (i == 0)
            dp[i] = 0;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = capacity; j >= 0; --j)
            if (j - w[i] >= 0 && dp[j - w[i]] != -1 && dp[j] < v[i] + dp[j - w[i]]) {
                    dp[j] = v[i] + dp[j - w[i]];

//                    printf("j :: %lld i :: %lld v[i] :: %lld  w[i] :: %lld dp[j - w[i]] :: %lld\n", j, i, v[i], w[i], dp[j - w[i]]);
            }


//        for (int i = 0; i <= capacity; ++i)
//            cout << dp[i] << " ";

//        cout << endl;
    }

    long long max_ans = 0;

    for (int i = 0; i <= capacity; ++i)
        if (dp[i] > max_ans)
            max_ans = dp[i];

    cout << max_ans << endl;
}

Measured memory_bytes: 4332
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  long long int n,wait[10000],customer[10000],total;
  while(cin >> n) {
    if(n == 0) break;
    long long int wait[10000] = {0},customer[10000] = {0},total = 0;
    for(int i=0;i<n;i++) {
      cin >> customer[i];
    }

    sort(customer,customer+n);

    for(int i=0;i<n;i++) {
      if(i==0) {
        wait[i] = 0;
      }
      else {
        wait[i] = wait[i-1] + customer[i-1];
      }
      total += wait[i];
    }
    cout << total << endl;
  }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long nn = 0;
        for (int i = 0; i < n; i++) {
            nn += sc.nextInt();
        }
        long mm = 0;
        for (int i = 0; i < m; i++) {
            mm += sc.nextInt();
        }
        System.out.println(nn * mm);
    }
}


Measured memory_bytes: 100596
#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>adj[M];
bool mark[M];
int ind;
int a[M],b[M];
void dfs(int v)
{
    mark[v]=1;
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(mark[u] || (u==a[ind] && v==b[ind]) || (u==b[ind] && v==a[ind]))
            continue;
        dfs(u);
    }
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m;
	cin>>n>>m;
	int ans=0;
	for(int i=1;i<=m;i++)
        cin>>a[i]>>b[i],adj[a[i]].pb(b[i]),adj[b[i]].pb(a[i]);
    for(int i=1;i<=m;i++)
    {
        ind=i;
        int cnt=0;
        for(int j=1;j<=n;j++)
            mark[j]=0;
        for(int j=1;j<=n;j++)
        {
            if(!mark[j])
                dfs(j),cnt++;
        }
        if(cnt!=1)
            ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 6272
# -*- coding: utf-8 -*-

H,W,A,B = map(int, input().split())
mod = (10 ** 9 + 7)

# 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく
factorial = [1] * (H+W)
factorial[0] = 1
factorial[1] = 1
for i in range(2,H+W):
    factorial[i] = factorial[i-1] * i % mod

inverse = [1] * (H+W)
# フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)
# powに第三引数入れると冪乗のmod付計算を高速にやってくれる
inverse[H+W-1] = pow(factorial[H+W-1], mod-2, mod)
for i in range(H+W-2, 0, -1):
    # 最後から戻っていくこのループならH+W回powするより処理が速い
    inverse[i] = inverse[i+1] * (i+1) % mod

# 組み合わせの数だけ返してくれる関数(自作)
def nCr(n, r):
    # 10C7 = 10C3
    r = min(r, n-r)
    # 分子の計算
    numerator = factorial[n]
    # 分母の計算
    denominator = inverse[r] * inverse[n-r] % mod
    return numerator * denominator % mod

h = H - A
w = B + 1
ans = 0
# マスを右上に1つずつずらして、必ず通る場所でパターンを足し合わせていく
while h > 0 and w <= W:
    ans = (ans + nCr(h+w-2, h-1) * nCr(H-h+W-w, H-h)) % mod
    h -= 1
    w += 1

print(ans)

Measured memory_bytes: 18804
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>

using namespace std;
typedef long long ll;

ll a, x, d;
int main() {
  a = 100;
  scanf("%lld", &x);
  while (a < x) {
    d++;
    a = ll(a * 1.01);
  }
  printf("%lld\n", d);
  return 0;
}



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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    char col[26]; col[0] = 'A';
    rep(i, 25) col[i+1] = col[i] + 1;
    int H, W; cin >> H >> W;
    string S[H][W]; rep(i, H) rep(j, W) cin >> S[i][j];
    rep(i, H){
        rep(j, W){
            if(S[i][j] == "snuke"){
                cout << col[j] << i+1 << endl;
                return 0;
            }
        }
    }
     return 0;
}

Measured memory_bytes: 256
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

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

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	cnt := 0
	for i := 1; i <= n; i++ {
		if len(strconv.Itoa(i))%2 == 1 {
			cnt++
		}
	}
	fmt.Fprintln(write, cnt)
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
string S;
cin >> S;

if(S == "Sunny") {
    print("Cloudy");
    return 0;
}
if(S == "Cloudy"){
    print("Rainy");
    return 0;
}
if(S == "Rainy"){
    print("Sunny");
    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 n=scan.nextInt();
			int k=scan.nextInt();
			int ar[]=new int[n];
			for(int i=0;i<n;i++)
			{
				ar[i]=scan.nextInt();
				
			}
			int min=Integer.MAX_VALUE;
			for(int i=0;i<n-k+1;i++)
			{
				if(ar[i]>0)
				{
					min=Math.min(min, ar[i+k-1]);
				}else if(ar[i]<0 && ar[i+k-1]<0)
				{
					min=Math.min(min,-ar[i]);
				}else {
					min=Math.min(min,Math.min(-2*ar[i]+ar[i+k-1],2*ar[i+k-1]-ar[i]));
				}
			}
			System.out.println(min);
				
			
		}
	}


Measured memory_bytes: 53024
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr int max_n = 100005;

int N,M;
vector<int> g[max_n];

int main(){
    cin >> N >> M;
    rep(i,M){
        int a,b; cin >> a >> b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }


    int center = 0;

    set<int> st;
    st.insert(center);

    deque<int> deq;
    deq.push_front(center);

    if(g[center].size() == 1){
        int now = center;
        while(1){
            int nxt = -1;
            for(int nxt2 : g[now]) if(!st.count(nxt2)){
                nxt = nxt2;
                break;
            }
            if(nxt == -1) break;
            st.insert(nxt);
            deq.push_back(nxt);
            now = nxt;
        }
    }else{
        int now = center;
        while(1){
            int nxt = -1;
            for(int nxt2 : g[now]) if(!st.count(nxt2)){
                nxt = nxt2;
                break;
            }
            if(nxt == -1) break;
            st.insert(nxt);
            deq.push_back(nxt);
            now = nxt;
        }

        now = center;
        while(1){
            int nxt = -1;
            for(int nxt2 : g[now]) if(!st.count(nxt2)){
                nxt = nxt2;
                break;
            }
            if(nxt == -1) break;
            st.insert(nxt);
            deq.push_front(nxt);
            now = nxt;
        }
    }

    cout << deq.size() << endl;
    for(int v : deq){
        cout << v+1 << endl;
    }
}


Measured memory_bytes: 11392
//スマホから
#include<bits/stdc++.h>
using namespace std;

int f[100100];
long long b[100100];
int x[100100],y[100100];
int n,k;

int main(void)
{
  int i;
  cin >> n >> k;
  for(i=0;i<n;i++) {
    f[i]=0; b[i]=1;
  }
  f[0]=1;
  for(i=0;i<k;i++) {
    cin >> x[i] >> y[i];
    x[i]--;y[i]--;
  }
  
  for(i=0;i<k;i++) {
    b[x[i]]--;
    b[y[i]]++;
    if(f[x[i]]==1) f[y[i]]=1;
    if(b[x[i]]==0) f[x[i]]=0;
  }
  
  int cnt=0;
  for(i=0;i<n;i++){
    cnt+=f[i];
  }
  cout << cnt << endl;
}
    
  
  
    

Measured memory_bytes: 2176
n, k = map(int, input().split())
s = input()

prev_R = '1'
for R in range(n):
    if (prev_R, s[R]) == ('1', '0'):
        k -= 1
        if k < 0:
            R -= 1
            break
    prev_R = s[R]

ans = R+1
for L in range(n-1):
    if (s[L], s[L+1]) != ('0', '1'):
        continue
    R += 1
    while R < n-1 and (s[R], s[R+1]) != ('1', '0'):
        R += 1
    if ans < R-L:
        ans = R-L
print(ans)

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

int main(){
    int N, Q;
    string S;
    cin >> N >> S >> Q;

    while(Q--){
        int K;
        cin >> K;

        int64_t d = 0, m = 0, dm = 0, ans = 0;
        for(int i=0; i<N; i++){
            if(i-K >= 0){
                if(S[i-K] == 'D'){
                    d--;
                    dm -= m;
                }else if(S[i-K] == 'M'){
                    m--;
                }
            }
            
            if(S[i] == 'D'){
                d++;
            }else if(S[i] == 'M'){
                m++;
                dm += d;
            }else if(S[i] == 'C'){
                ans += dm;
            }
        }

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

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

using namespace std;

typedef long long ll;

int main()
{
  int n;
  ll C;
  scanf("%d %lld", &n, &C);
  vector<ll> dist(n, 0), calories(n, 0);
  for (int i = 0; i < n; ++i) {
    ll x, v;
    scanf("%lld %lld", &x, &v);
    dist[i] = x;
    calories[i] = v;
  }

  vector<ll> cwise(n, 0), ccwise(n, 0);
  ll val = calories[0] - dist[0];
  cwise[0] = max(0LL, val);
  for (int i = 1; i < n; ++i) {
    val += calories[i] - (dist[i] - dist[i - 1]);
    cwise[i] = max(val, cwise[i - 1]);
  }
  val = calories[n - 1] - (C - dist[n - 1]);
  ccwise[n - 1] = max(0LL, val);
  for (int i = n - 2; i >= 0; --i) {
    val += calories[i] - (dist[i + 1] - dist[i]);
    ccwise[i] = max(val, ccwise[i + 1]);
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, cwise[i]);
    ans = max(ans, ccwise[i]);
    if (i + 1 < n) {
      // clockwise => counter clockwise
      ans = max(ans, cwise[i] - dist[i] + ccwise[i + 1]);
      // counter clockwise => clockwise
      ans = max(ans, ccwise[i + 1] - (C - dist[i + 1]) + cwise[i]);
    }

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

  return 0;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] str = sc.next().toCharArray();
        if (n % 2 == 1) {
            System.out.println("No");
            return;
        }
        for (int i = 0; i < n / 2; i++) {
            if (str[i] != str[n / 2 + i]) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 21204
N = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y != 0:
        x, y = y, x%y
    return x

L = [0]
R = [0]
for i in range(N):
    L.append(gcd(A[i], L[i]))
    R.append(gcd(A[-i-1], R[i]))

R.reverse()

M = []
for i in range(0, N):
    M.append(gcd(L[i], R[i+1]))

print(max(M))


Measured memory_bytes: 14524
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeMap;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let k: usize = read();
    let n: usize = read();
    let a: Vec<usize> = (0..n).into_iter().map(|_| read()).collect();
    let mut m = 0;
    let mut l = 0;
    for i in 0..n {
        let b = (k - (a[i % n]) + (a[(n + i - 1) % n])) % k;
        let c = (k - (a[(n + i - 1) % n]) + (a[i % n])) % k;
        l += min(b, c);
        m = std::cmp::max(std::cmp::min(b, c), m);
    }
    let ret = l - m;
    println!("{}", ret);
}


Measured memory_bytes: 6396
n,m,l=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(m):
    b.append(list(map(int,input().split())))
c = [[0] * l for i in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]
    print(*c[i])


Measured memory_bytes: 7032
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		char[] c = S.toCharArray();
		for (int i = 0; i < N; i++) {
			if (i == K - 1) {
				if (c[i] == 'A')
					c[i] = 'a';
				else if (c[i] == 'B')
					c[i] = 'b';
				else
					c[i] = 'c';
			}
		}
		for (int i = 0; i < N; i++)
			System.out.print(c[i]);

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 20948
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}

int main() {
	int n, a, c[111111], i, ans = 0,count=0;
	cin >> n;
	for (i = 1; i <= 100000; i++)
		c[i] = 0;
	for (i = 0; i < n; i++) {
		cin >> a;
		if (c[a] == 0)
			ans++;
		c[a]++;
	}
	for (i = 1; i <= 100000; i++) {
		if (c[i] % 2 == 0 && c[i] > 0)
			count++;
	}
	if (count % 2 == 1)
		ans--;
	cout << ans << endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int main(){
	int a,b;
	cin>>a>>b;
	if(a%2&&b%2)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long tot = 1;
		for(int i=0;i<N;i++) tot *= 3L;
		
		long odd = 1;
		for(int i=0;i<N;i++){
			odd *= (A[i] % 2 == 0) ? 2 : 1;
		}
		Console.WriteLine(tot - odd);
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

using namespace std;

#define ll long long
#define MAXN 20
#define MAXM 2000005
#define bp(x) __builtin_popcountll(x)

ll n, a[MAXN][MAXN], c[MAXM], dp[MAXM];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) cin >> a[i][j];
    for (int mask = 0; mask < (1 << n); mask++){
        for (int i = 0; i < n; i++){
            if (!((mask >> i)&1)) continue;
            for (int j = i + 1; j < n; j++){
                if (!((mask >> j)&1)) continue;
                c[mask] += a[i][j];
            }
        }
    }
    for (int s = 0; s < (1 << n); s++) dp[s] = c[s];
    for (int s = 1; s < (1 << n); s++){
        for (int j = s; j > 0; j = s&(j-1))
            dp[s] = max(dp[s], dp[j] + c[s^j]);
    }
    cout << dp[(1<<n) - 1];
    
    return 0;
}


Measured memory_bytes: 2944
#include<stdio.h>
int main()
{
    int r,i,k=1;
    scanf("%d",&r);
    char s[r+2];
    scanf("%s",s);
    if(r%2)
        printf("No\n");
    else
    {
        for(i=0;i<r/2;i++)
        {
            if(s[i]!=s[i+r/2])
            {
                k=0;
                break;
            }
        }
        if(k)
            printf("Yes\n");
        else
            printf("No\n");
    }
}


Measured memory_bytes: 128
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
#define int long long

void solve() {
	int n; cin >> n;
    int cnt = 0;
    int n_ = n;
    int X; int Y = n_ % 10;
    while(n_ != 0) {
        X = n_ % 10;
        n_ /= 10;
        ++cnt;
    }
    //cerr << X << " " << Y << endl;
    //cerr << cnt << endl;
    int ans = 0;
    for(int a = 1; a <= n; ++a) {
        int y = a % 10;
        if(y == 0) continue;
        int a_ = a, x;
        while(a_ != 0) {
            x = a_ % 10;
            a_ /= 10;
        }
        //cerr << x << " " << y << endl;
        if(x == y) {
            if(x <= n) ++ans;
        }
        for(int k = 2; k <= 6; ++k) {
            if(k > cnt) continue;
            else if(k < cnt) {
                int t = 1LL;
                rep(i, k - 2) t *= 10LL;
                ans += t;
            }
            else {
                if(y < X) {
                    int t = 1LL;
                    rep(i, k - 2) t *= 10LL;
                    ans += t;
                } else if(y > X) {
                    continue;
                } else {
                    int n__ = n;
                    int t = 1LL;
                    rep(i, cnt - 1) t *= 10LL;
                    n__ -= X * t;
                    n__ /= 10;
                    if(Y >= x) {
                        n__ ++;
                    }
                    ans += n__;
                }
            }
        }
        //cerr << a << " " << ans << endl;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll a, b;
  cin >> a >> b;
  if(a+b==15) cout << '+' << newl;
  else if(a*b==15) cout << '*' << newl;
  else cout << 'x' << newl;
  return 0;
}


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


int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    for(int i=0;i<100;i++){
        C-=B;
        if(C<=0){
            cout << "Yes" << endl;
            break;
            }
        A-=D;
        if(A<=0){
            cout << "No" << endl;
            break;
            }
    }
}

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

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

  int g[15][15];
  rep(i, 15) rep(j, 15) g[i][j] = -1;
  rep(i, n){
    int a;
    cin >> a;
    rep(j, a){
      int x, y;
      cin >> x >> y;
      x--;
      g[i][x] = y;
    }
  }

  int ans = 0;
  rep(i, 1<<n){
    vector<int> d(n);
    rep(j, n) if(i>>j&1){
      d[j] = 1;
    }
    bool ok = true;
    rep(j, n){
      if(d[j]){
        rep(k, n){
          if(g[j][k] == -1) continue;
          if(g[j][k] != d[k]) ok = false;
        }
      }
    }
    if(ok) ans = max(ans, __builtin_popcount(i));
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111



	void solve(){

		
		ini(n);
		vi morty(n);
		FOR(i,0,n){
			in(morty[i]);
		}
		if(morty[0] != 0)return out(-1);
		FOR(i,1,n)if(morty[i]-morty[i-1]>1)return out(-1);
		map<int,int> map1;
		int rick = 0;
		FOR(i,0,n){
			map1[i-morty[i]] = morty[i];	
		}
		FORR(x,map1)rick+=x.second;
		out(rick);




	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 14336
import sys
import time
import random
import math

t_start = time.perf_counter()

N = 26
D = int(input())

c_list = list(map(int, input().split()))

s_table = []
for _ in range(D):
	s_table.append(list(map(int, input().split())))

last = [-1] * N
data = []
satisfaction = 0
for i in range(D):
	max_c = 0
	max_s = None
	s_list = s_table[i]
	for j in range(N):
		s = s_list[j]
		for k in range(N):
			if k != j:
				s -= c_list[k] * (i - last[k])
		if max_s == None or s > max_s:
			max_s = s
			max_c = j
	data.append(max_c)
	satisfaction += max_s
	last[max_c] = i

print(satisfaction, file = sys.stderr)

def calc(data):
	last = [-1] * N
	satisfaction = 0
	for i in range(D):
		j = data[i]
		satisfaction += s_table[i][j]
		last[j] = i
		for k in range(N):
			satisfaction -= c_list[k] * (i - last[k])
	return satisfaction

def p(value_old, value_new, t):
	if value_new > value_old:
		return True
	else:
#		print(value_old - value_new, file = sys.stderr)
#		print(math.pow(math.e, (value_old - value_new) / t), file = sys.stderr)
		return math.pow(math.e, (value_new - value_old) / t) > random.random()

def optimize(satisfaction, data):
	t_end = t_start + 1.8
	T = 10000
	d = 0.9999
	best = satisfaction
	best_data = list(data)
	tmp_data = list(data)
	while True:
		if time.perf_counter() > t_end:
			return best, best_data
		i = random.randrange(D)
		j = random.randrange(N)
		while j == data[i]:
			j = random.randrange(N)
		tmp_data[i] = j
		tmp_s = calc(tmp_data)
#		if tmp_s < satisfaction:
#			print(best, T, satisfaction, satisfaction - tmp_s, math.pow(math.e, -(satisfaction - tmp_s) / T), file = sys.stderr)
		if p(satisfaction, tmp_s, T):
#			if p(best, tmp_s, T):
			satisfaction = tmp_s
			data[i] = j
			if satisfaction > best:
				best = satisfaction
				best_data = list(data)
#			print(T, tmp_s, file = sys.stderr)
		T *= d

satisfaction, data = optimize(satisfaction, data)

print(calc(data), file = sys.stderr)

for j in data:
	print(j + 1)


Measured memory_bytes: 82376
import java.util.Scanner;

/**
 * @author yoshizaki
 * ABC 086
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String ans = "";
        if((a*b)%2 ==1) {
            ans = "Odd";
        } else {
            ans = "Even";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 50;
const int INF = 1e18 + 50;
int S[MAXN], T[MAXN];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int A, B, Q; cin >> A >> B >> Q;
    S[0] = -INF; S[A+1] = INF;
    T[0] = -INF; T[B+1] = INF;
    for (int i=1; i<=A; i++) cin >> S[i];
    for (int i=1; i<=B; i++) cin >> T[i];
    sort(S,S+A+2);
    sort(T,T+B+2);
    for (int i=0; i<Q; i++){
        int x; cin >> x;
        int idx = lower_bound(S,S+A+2,x)-S;
        int sl = S[idx-1];
        int sr = S[idx];
        idx = lower_bound(T,T+B+2,x)-T;
        int tl = T[idx-1];
        int tr = T[idx];
        //cout << sl << " " << sr << " " << tl << " " << tr << "\n";
        int ans = INF;
        ans = min(ans, sr-x+min(abs(sr-tr), abs(sr-tl)));
        ans = min(ans, x-sl+min(abs(sl-tl), abs(sl-tr)));
        ans = min(ans, tr-x+min(abs(tr-sr), abs(tr-sl)));
        ans = min(ans, x-tl+min(abs(tl-sr), abs(tl-sl)));
        cout << ans << "\n";
    }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
vector <long long> vect[200100];
long long ki[200100],visited[200100];
void dfs(long long count1,long long parent)
{
    visited[parent]=1;
    for(int i=0;i<vect[parent].size();i++)
    {
        if(visited[vect[parent][i]]==0)
        {
            ki[vect[parent][i]]+=count1;
            dfs(ki[vect[parent][i]],vect[parent][i]);
        }
    }
}
int main()
{
    long long n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++)
    {
        long long a,b;
        cin>>a>>b;
        vect[a].push_back(b);
        vect[b].push_back(a);
    }
    for(int i=0;i<q;i++)
    {
            long long a,b;
            cin>>a>>b;
            ki[a]+=b;
    }
    dfs(ki[1],1);
    for(int i=1;i<=n;i++)
        cout<<ki[i]<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 25856
s=input()
i=0
j=len(s)-1
ans=0
while i<j:
    while s[i]==s[j]=="x":
        i+=1
        j-=1
        if i>j:break
    if i>j:break    
    while s[i]=="x":
        i+=1
        ans+=1
        if i>j:break
    if i>j:break
    while s[j]=="x":
        j-=1
        ans+=1
        if i>j:break
    if i>j:break
    if s[i]!=s[j]:
        ans=-1
        break
    i+=1
    j-=1
    if i>j:break
print(ans)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    Int A, B; cin >> A >> B;
    for (Int bit = 1LL << 60; bit; bit >>= 1) {
        if ((A & bit) && (B & bit)) A ^= bit, B ^= bit;
        else if (!(A & bit) && (B & bit)) break;
    }
    vector<Int> bits;
    for (Int bit = 1LL << 60; bit; bit >>= 1) {
        if (B & bit) bits.push_back(bit);
    }
    if (bits.empty()) { cout << 1 << '\n'; return 0; }
    Int ans = 0;
    Int f1 = A, t1 = (bits[0] - 1);
    ans += t1 - f1 + 1;
    Int f2 = bits[0], t2 = bits[0] + (bits.size() >= 2 ? (bits[1] << 1) - 1 : 0);
    ans += t2 - f2 + 1;
    Int f3 = bits[0] | A, t3 = (bits[0] << 1) - 1;
    ans += t3 - max(t2 + 1, f3) + 1;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num[200];
ll ans[200];
int main()
{
	num[0]=1;
	int i;
	for(i=1;i<=14;i++)
	{
		num[i]=num[i-1]*26;
	}
	ll n;
	int cnt=0;
	char ch;
	cin>>n;
	if(n<=26)
	{
		n--; 
	    ch='a'+n;
		cout<<ch;
		return 0; 
	}
	for(i=1;i<=14;i++)
	{
		if(n-num[i]<=0)
		{
			cnt=i;
			break;
		}
		n-=num[i];
	}
	if(n==0)
	{
		for(i=1;i<=cnt;i++) cout<<"z";
		return 0;
	}
	n--;
	int sum=1;
	while(n)
	{
		ll tmp=n%26;
		ans[sum++]=tmp;
		n=n/26;
	}
	for(i=cnt;i>=1;i--)
	{
		ch=ans[i]+'a';
		cout<<ch;
	}
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>

using namespace std;
typedef long long ll;

int main()
{

    ll N, K;
    cin >> N >> K;

    ll result = 0;
    for (int i = K+1; i <= N; ++i)
    {
        result += (N / i) * (i - K);
        if (N % i >= K) result += N % i - K + 1;
    }
    if (K == 0) result -= N;
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;

typedef long double ld;

int n;
vector<int> t[150000];
bool used[150000];
vector<int> g[150000];
ld e[150000];
ld ans[150000];

void make_graph(int i){
    used[i] = true;
    for(int v: t[i]){
        if(!used[v]){
            g[i].push_back(v);
            make_graph(v);
        }
    }
}

ld dfs(int i){
    ld c = 0;
    for(int v: g[i]){
        c += dfs(v) + 1;
    }
    return e[i] = c / max((int)g[i].size(), 1);
}

void solve(int i, ld u){
    if(i == 0){
        ans[i] = e[i];
        ld s = 0;
        for(int v: g[i]){
            s += e[v];
        }
        for(int v: g[i]){
            solve(v, g[i].size() == 1 ? 0 : (s - e[v]) / (g[i].size() - 1) + 1);
        }
        return;
    }
    ans[i] = (u + 1 + g[i].size() * e[i]) / (g[i].size() + 1);
    ld s = 0;
    for(int v: g[i]){
        s += e[v];
    }
    for(int v: g[i]){
        solve(v, (s - e[v] + u) / g[i].size() + 1);
    }
}

int main(){
    cin >> n;
    rep(i, n - 1){
        int u, v;
        cin >> u >> v;
        t[u - 1].push_back(v - 1);
        t[v - 1].push_back(u - 1);
    }

    make_graph(0);

    dfs(0);

    solve(0, -1);

    rep(i, n){
        cout << fixed << setprecision(10) << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 25728
#include <iostream>

using namespace std;

int main()
{
	int n;
	do {
		int sum = 0;
		cin >> n;
		if (n == 0) break;
		for (int i = 2;i < n ;i++) {
			if (i % 2 == 0) {
			   if ((n % (i / 2) == 0) && (((n / i) - (i / 2) + 1) > 0) && (n % i != 0)) {
					sum++;
			   }
			} else if (n % i == 0 && (n / i - (i - 1) / 2 > 0)) {
				sum++;
			}
		}
		cout << sum << endl;
	}while (n != 0) ;
	return 0;
}


Measured memory_bytes: 2968
#include<stdio.h>

int main()
{
	int a ,b;
	char(op);
	while(scanf("%d %c %d",&a,&op,&b))
	{
		if(op == '?')
		{
			break;
		}
		switch(op)
		{
			case'+':
				printf("%d\n",a+b);
				break;
			case'-':
				printf("%d\n",a-b);
				break;
			case'*':
				printf("%d\n",a*b);
				break;
			case'/':
				printf("%d\n",a/b);
				break;
		}
	}
	return 0;
}


Measured memory_bytes: 2100
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
	int a,b;
    cin>>a>>b;
    if(a*500>=b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

ll ModPow(ll num, ll n) {
	ll tmp = 1;
	rep(i, n) {
		tmp *= num;
		tmp %= MOD;
	}
	return tmp;
}

int main()
{
	ll n;
	cin >> n;
	ll ans = ModPow(10, n) - ((2 * ModPow(9, n)) % MOD);
	ans %= MOD;
	if (ans < 0) ans += MOD;
	ans += ModPow(8, n);
	ans %= MOD;
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}


Measured memory_bytes: 3620
N = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))

ans = 0
count_i = 0
b_con = 0

for i in a_list:
    count_i += 1 
    ans += b_list[i-1]
    if b_con+1 == i and i != 1:
        ans += c_list[i-2]
    b_con = i

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; ++i)

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    ans = (n * (n-1)) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string word;
    bool flag = false;
    cin>>word;
    for(int i=0;i<word.length()-1;i++){
        if((word[i]=='B'&&word[i+1]=='A')||(word[i]=='A'&&word[i+1]=='B')){
            flag = true;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256