akhauriyash/Code-Regression huggingface dataset:
import itertools
import sys

h, w = map(int, input().split())

a = [input() for i in range(h)]
words = list(set(itertools.chain(*a)))
at = list(itertools.chain(*a))

mods = []
for word in words:
    for i in range(at.count(word) // 4):
        mods.append(4)
    mod = at.count(word) % 4
    if mod:
        mods.append(mod)

mods = list(sorted(mods))
def count_down(l, n):
    for i in range(len(l)):
        if l[i] - n >= 0:
            l[i] -= n
            if not l[i]:
                del l[i]
            return True
    return False

if h % 2 and w % 2:
    flg = True
    for i in range(w // 2 + h // 2):
        flg = count_down(mods, 2)
    if flg and count_down(mods, 1) and mods.count(4) == len(mods):
        print("Yes")
        sys.exit()

elif h % 2:
    flg = False
    for i in range(w // 2):
        flg = count_down(mods, 2)
    if flg and mods.count(4) == len(mods):
        print("Yes")
        sys.exit()

elif w % 2:
    flg = False
    for i in range(h // 2):
        flg = count_down(mods, 2)
    if flg and mods.count(4) == len(mods):
        print("Yes")
        sys.exit()

else:
    if mods.count(4) == len(mods):
        print("Yes")
        sys.exit()

print("No")


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

int main(){
	int N; cin >> N;
	double ans = 0;
	for(int i = 0 ; i < N ; i++){
		double x; string u; cin >> x >> u;
		if(u == "BTC"){
			ans += 380000.0*x;
		}else{
			ans += x;
		}
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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 int W_MAX=20, H_MAX=20;
char maze[W_MAX][H_MAX];
P diff[4] = {make_pair(1,0), make_pair(0,1), make_pair(-1, 0), make_pair(0, -1)};


int main(){
    int h, w; cin >> h >> w;
    rep(j, h){
        rep(i, w){
            cin >> maze[i][j];
        }
    }

    // bfsで全頂点距離算出
    int ans = 0;
    rep(yy, h){
        rep(xx, w){
            if(maze[xx][yy]=='#') continue;

            int dist[W_MAX][H_MAX];
            rep(j, h){
                rep(i, w){
                    dist[i][j]=-1;
                }
            }
            queue<P> points;

            points.push(make_pair(xx,yy)); //始点
            dist[xx][yy] = 0;
            while(!points.empty()){
                P current = points.front(); points.pop();
                // 隣接頂点が未探索ならば詰める
                rep(i, 4){
                    int x=current.first+diff[i].first;
                    int y=current.second+diff[i].second;
                    if(x<0 || x>=w || y<0 || y>=h){
                        continue;
                    }
                    if(maze[x][y]=='.' && dist[x][y]==-1){
                        points.push(make_pair(x, y));
                        dist[x][y] = dist[current.first][current.second]+1;
                    }
                }
            }
            // 最長を算出
            int longest = 0;
            rep(j, h){
                rep(i, w){
//                    cout << dist[i][j] << " ";
                    longest = max(longest, dist[i][j]);
                }
            }
            ans = max(ans, longest);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;


namespace aizu
{
	public class EntryPoint
	{
		public static int[] Split(string line)
		{
			return Regex.Split(line, " ").Select(x => int.Parse(x)).ToArray();
		}
		public static void Main()
		{
			var line = Console.ReadLine();
			
			var v = Split(line);
			
			var W = v[0];
			var H = v[1];
			var x = v[2];
			var y = v[3];
			var r = v[4];
			
			var R = new Rectangle(0, 0, W, H);
			var R2 = new Rectangle(x - r, y - r, r * 2, r * 2);
			
			if (R.Contains(R2))
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
			
			
			
			
			
			
		}
	}


}

Measured memory_bytes: 21720
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	String N = in.next();
        	int count = 0;
        	for(int i = 0; i < 4; i++) {
        		if(N.charAt(i) == '2') {
        			count++;
        		}
        	}
        	out.println(count);

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

struct cake {
    int w, d;

    cake() {}
    ~cake() {}

    cake(int a, int b):
        w(a), d(b) {}

    int get_area() const {
        return w * d;
    }

    cake separate(int s) {
        s %= 2 * (w + d);

        int new_w = w, new_d = d;

        if (s < w) {
            new_w = max(s, w-s);
            w = min(s, w-s);
        } else if (s < w + d) {
            new_d = max(s-w, w+d-s);
            d = min(s-w, w+d-s);
        } else if (s < 2 * w + d) {
            new_w = max(s-w-d, 2*w+d-s);
            w = min(s-w-d, 2*w+d-s);
        } else {
            new_d = max(s-2*w-d, 2*w+2*d-s);
            d = min(s-2*w-d, 2*w+2*d-s);
        }

        return cake(new_w, new_d);
    }

    bool operator < (const cake& o) const {
        return get_area() < o.get_area();
    }
};

void solve(int n, int w, int d) {
    int p, s;

    vector<cake> cakes(0);
    cakes.push_back(cake(w, d));

    for (int j = 0; j < n; ++j) {
        cin >> p >> s;
        
        cake target = cakes[--p];
        cakes.erase(begin(cakes) + p);

        cake new_cake = target.separate(s);

        cakes.push_back(target);
        cakes.push_back(new_cake);

        // cout << "<DEBUG>" << endl;
        // cout << "::" << p << " " << s << endl;
        // for (int j = 0; j < cakes.size(); ++j) {
        //     printf("id:%d, width:%d, depth:%d\n", j, cakes[j].w, cakes[j].d);
        // }
        // cout << "</DEBUG>" << endl;
    }

    sort(begin(cakes), end(cakes));

    for (int j = 0; j < cakes.size(); ++j) {
        if (j > 0) {
            cout << " ";
        }
        cout << cakes[j].get_area();
    }
    cout << endl;
}

int main () {
    int n, w, d;

    while(true) {
        cin >> n >> w >> d;
        if (n == 0 && w == 0 && d == 0) {
            break;
        }
        solve(n, w, d);
    }

    return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> > G(n);

  vector<int> used(n,0);
  deque<int> ans;
  
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);

    if(i) continue;
    ans.emplace_front(a);
    ans.emplace_back(b);
    used[a]=used[b]=1;
  }
  
  while(1){
    int v=ans.front();
    int idx=-1;
    for(int u:G[v])
      if(!used[u]) idx=u;
    if(idx<0) break;
    ans.emplace_front(idx);
    used[idx]=1;
  }

  while(1){
    int v=ans.back();
    int idx=-1;
    for(int u:G[v])
      if(!used[u]) idx=u;
    if(idx<0) break;
    ans.emplace_back(idx);
    used[idx]=1;
  }
  
  cout<<ans.size()<<endl;
  for(int i=0;i<(int)ans.size();i++){
    if(i) cout<<" ";
    cout<<ans[i]+1;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 7040
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

lint segdata[(1<<20)-1];

lint neutral(){
    return -LINF; //単位元
}
lint calc(lint a,lint b){
    return max(a,b); //演算
}
void seginit(){
    rep(i,(1<<20)-1) segdata[i]=neutral();
}
void update(lint i,lint x){ // i番目の値をxに更新
    i+=(1<<19)-1;
    segdata[i]=x;
    while(i>0){
        i=(i-1)/2;
        segdata[i]=calc(segdata[i*2+1],segdata[i*2+2]);
    }
}
lint seg(lint a,lint b,lint k,lint l,lint r){
    if(r<=a || b<=l) return neutral();
    if(a<=l && r<=b) return segdata[k];
    else{
        lint left=seg(a,b,k*2+1,l,(l+r)/2);
        lint right=seg(a,b,k*2+2,(l+r)/2,r);
        return calc(left,right);
    }
}
lint query(lint a,lint b){
    return seg(a,b+1,0,0,1<<19); //a~b(閉区間）の範囲での演算
}
 
int main(void){
    seginit();
    int H,W,M;
    cin >> H >> W >> M;
    rep(i,W) update(i,0);
    int h[M],w[M];
    rep(i,M) cin >> h[i] >> w[i];
    rep(i,M) h[i]--,w[i]--;
    vector<int> itm[H];
    rep(i,M){
        itm[h[i]].push_back(w[i]);
        update(w[i],query(w[i],w[i])+1);
    }
    lint ans=0;
    rep(i,H){
        rep(j,itm[i].size()) update(itm[i][j],query(itm[i][j],itm[i][j])-1);
        lint cmp=itm[i].size();
        lint add=0;
        add=query(0,W-1);
        cmp+=add;
        ans=max(ans,cmp);
        rep(j,itm[i].size()) update(itm[i][j],query(itm[i][j],itm[i][j])+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 30584
"""
重さと価値がそれぞれw_i,v_iであるようなn個の品物がある.
これらの品物の中から, 重さの総和がWを超えないように選んだ時の,
価値の総和の最大値を求めよ.
1<=n<=100, 1<=w_i<=10^7, 1<=v_i<=100, 1<=W<=10^9
"""
#-------------------------------------------------------------------------------

#入力
INF=2*10**9
n,W = map(int,input().split())
w=[0]*n
v=[0]*n
for i in range(n):
    w[i],v[i] = map(int, input().split())
max_v=max(v)
dp = [[INF for i in range(n*max_v+1)] for j in range(n+1)]

#ここからメイン
dp[0][0]=0
for i in range(n):
    for j in range(n*max_v+1):
        if j<v[i]:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i])
ans=0
for i in range(n*max_v+1):
    if dp[n][i]<=W:
        ans=i
print(ans)


Measured memory_bytes: 173040
#include <iostream>

using namespace std;

int main(){
    int i,j,N;
    cin >> N;

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

    int M = 0;
    int k = 0;

    for(i=N;i>0;i--){
        int val = 0;
        for(j=2;i*j<=N;j++){
            val+=b[i*j];
        }
        if(val%2!=a[i]){
            b[i]=1;
            M++;
            k=max(k,i);
        }
    }
    cout << M << endl;
    for(i=1;i<=N;i++){
        if(b[i]==1){
            M--;
            M==0 ? cout<<i<<endl : cout<<i<<" ";
        }
    }
}


Measured memory_bytes: 2432
import java.util.*;

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

	class Pair{
		int h;
		int w;
		Pair(int h, int w){
			this.h=h;
			this.w=w;
		}
	}

	char g[][];
	int d[][];
	int INF = 1001001001;
	int dw[] = {1,0,-1,0};
	int dh[] = {0,1,0,-1};
	int H;
	int W;
	public void run() {
		Scanner sc = new Scanner(System.in);
		H=sc.nextInt();
		W=sc.nextInt();
		g = new char[H][W];
		d = new int[H][W];
		int wc=0;
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				d[i][j]=INF;
			}
		}
		for(int i=0; i<H; i++) {
			g[i] = sc.next().toCharArray();
			for(int j=0; j<W; j++) {
				if(g[i][j]=='.') {
					wc++;
				}
			}
		}

		wc -= 2;

		bfs();

		if(d[H-1][W-1] == INF) {
			System.out.println(-1);
			sc.close();
			return;
		}

		wc -= d[H-1][W-1]-1;
		System.out.println(wc);

		sc.close();
	}

	private void bfs() {
		d[0][0]=0;
		ArrayDeque<Pair> q = new ArrayDeque<Pair>();
		q.add(new Pair(0,0));
		while(!q.isEmpty()) {
			Pair p = q.poll();
			for(int i=0; i<4; i++) {
				int sh = p.h+dh[i];
				int sw = p.w+dw[i];
				if(sw<0 || sw>=W || sh<0 || sh >=H || g[sh][sw] == '#') continue;
				if(d[sh][sw] == INF) {
					q.add(new Pair(sh, sw));
					d[sh][sw] = d[p.h][p.w]+1;
				}
			}
		}
	}
}


Measured memory_bytes: 21972
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double eps = 1e-6;
const int maxn = 1e5+10;
const ll mod = 1e9+7;
int n;
int a[maxn];

int comp(int x) {
    if (x > 0) {
        return 1;
    } else if (x < 0) {
        return -1;
    } else {
        return 0;
    }
}

int main() {
    scanf("%d",&n);
    for (int i = 0; i < n; i++) {
        scanf("%d",&a[i]);
    }
    int trend = 0;
    int ans = 1;
    for (int i = 1; i < n; i++) {
        if (trend) {
            if (trend > 0) {
                if (a[i] < a[i-1]) {
                    ans++;
                    trend = 0;
                }
            } else {
                if (a[i] > a[i-1]) {
                    ans++;
                    trend = 0;
                }
            }
        } else {
            trend = comp(a[i]-a[i-1]);
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int bfs[100][101];
int g[100][101];
int v[100];
int V[100][101];
int main(){
	int a,b,c,d,e,f;
	while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f),a){
		for(int i=0;i<100;i++)
			for(int j=0;j<101;j++)
				bfs[i][j]=99999999;
		for(int i=0;i<100;i++)v[i]=0;
		for(int i=0;i<c;i++){
			int p;
			scanf("%d",&p);
			v[p]=1;
		}
		for(int i=0;i<100;i++)
			for(int j=0;j<101;j++){
				g[i][j]=-1;V[i][j]=0;
			}
		for(int i=0;i<d;i++){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			g[x][y]=g[y][x]=z;
		}
		bfs[e][b]=0;
		priority_queue<pair<int,pair<int,int> > >Q;
		Q.push(make_pair(0,make_pair(e,b)));
		while(Q.size()){
			int cost=-Q.top().first;
			int at=Q.top().second.first;
			int val=Q.top().second.second;
			Q.pop();
			if(V[at][val])continue;
			V[at][val]=1;
			for(int i=0;i<a;i++){
				if(~g[at][i]&&val>=g[at][i]&&cost+g[at][i]<bfs[i][val-g[at][i]]){
					bfs[i][val-g[at][i]]=cost+g[at][i];
					Q.push(make_pair(-cost-g[at][i],make_pair(i,val-g[at][i])));
				}
			}
			if(v[at]&&val<b&&cost+1<bfs[at][val+1]){
				bfs[at][val+1]=cost+1;
				Q.push(make_pair(-cost-1,make_pair(at,val+1)));
			}
		}
		int ret=99999999;
		for(int i=0;i<=b;i++)ret=min(ret,bfs[f][i]);
		if(ret<99999999)printf("%d\n",ret);
		else printf("Help!\n");
	}
}

Measured memory_bytes: 1292
n = int(input())
w = list(map(int, input().split()))

s1 = sum(w[0:1])
s2 = sum(w[1:n])
top = abs(s1-s2)

for i in range(2,n) :
    s1 = sum(w[0:i])
    s2 = sum(w[i:n])
    wsum = abs(s1-s2)
    if top > wsum :
        top = wsum

print(top)

Measured memory_bytes: 3064
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	int n;
	int but[100000] = { -1 };
	int to = 0;
	int ans = 0;
	int c = 0;
	bool che[100000] = { 0 };

	cin >> n;

	rep(i, 0, n) {
		int c = 0;
		cin >> c;
		but[i] = c - 1;
	}

	int a = 0;

	while (a==0) {
		if (che[to]==true) {
			cout << -1 << endl;
			return 0;
		}
		if (but[to] == 1) {
			cout << ans + 1 << endl;
			return 0;
		}
		che[to] = { true };
		to = but[to];
		ans++;
	}


	return 0;
}


Measured memory_bytes: 768
#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;

int INF = 1001001001;

int main() {
    int N; cin >> N;
    vector<int> ans(26, INF);
    rep(i, N){
        string S; cin >> S;
        int ss = S.size();
        vector<int> now(26, 0);
        rep(j, ss){
            int a = S[j] - 'a';
            now[a]++;
        }
        rep(j, 26){
            ans[j] = min(ans[j], now[j]);
        }
    }

    rep(i, 26){
        int x = ans[i];
        rep(j, x){
            char c = 'a' + i;
            cout << c;
        }
    }

    cout << endl;

    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N+1);
	int num = 0;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = N; i >= 1; i--) {
		int buf = 0, j = i;
		while (j <= N) {
			buf += A[j];
			buf %= 2;
			j += i;
		}
		A[i] = buf;
		if (buf == 1) num++;
	}
	cout << num << endl;
	for (int i = 1; i <= N; i++) {
		if (A[i] == 1) cout << i << (i < N - 1 ? " " : "\n");
	}
}

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

int main()
{
    int n, m, c;
    cin >> n >> m >> c;

    vector<int> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int v = c;
        for (int j = 0; j < m; j++)
        {
            int a;
            cin >> a;
            v += b[j] * a;
        }
        if (v > 0)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

signed main(){
  string s;
  int ans;
  cin>>s>>ans;
  int a[10];
  int pos=0;
  a[0]=s[0]-'0';
  for(int i=1;i<s.length();i+=2){
    if(s[i]=='+'){
      a[++pos]=s[i+1]-'0';
    }else{
      int t=a[pos];
      a[pos]=t*(s[i+1]-'0');
    }
  }
  int sa=0;
  for(int i=0;i<=pos;i++){
    sa+=a[i];
  }
  int sb=s[0]-'0';
  for(int i=1;i<s.length();i+=2){
    if(s[i]=='+'){
      sb+=(s[i+1]-'0');
    }else{
      sb*=(s[i+1]-'0');
    }
  }
  if(ans==sa&&ans==sb)
    cout<<'U'<<endl;
  else if(ans==sa)
    cout<<'M'<<endl;
  else if(ans==sb)
    cout<<'L'<<endl;
  else
    cout<<'I'<<endl;
}



Measured memory_bytes: 3156
s = [i for i in input()]
s1, s2 = s[:(len(s)-1)//2], s[(len(s)+3)//2-1:]
for i in range(len(s1)//2):
    if s1[i] != s1[-i-1] or s2[i] != s2[-i-1]:
        print("No")
        exit()
for i in range(len(s)//2):
    if s[i] != s[-i-1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
S = input()
if len(set(S)) == 2:
	if S[0] == S[1] and S[2] == S[3]:
		print("Yes")
	elif S[0] == S[2] and S[1] == S[3]:
		print("Yes")
	elif S[0] == S[3] and S[1] == S[2]:
		print("Yes")
	else:
		print("No")
else:
	print("No")


Measured memory_bytes: 2940
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10;
int n , m , q , a , b , v[MAXN] , d[MAXN] , c[MAXN] , co[10 + 10][MAXN];
vector<int> adj[MAXN];
void dfs(int u , int d , int col)
{
	if(co[d][u])
		return;
	co[d][u] = col;
	if(!d)
		return;
	dfs(u , d - 1 , col);
	for(auto v : adj[u])
		dfs(v , d - 1 , col);
	return;
}
void input()
{
	cin >> n >> m;
	for(int i = 0 ; i < m ; i ++)
		cin >> a >> b , a -- , b -- , adj[a].pb(b) , adj[b].pb(a);
	cin >> q;
	for(int i = 0 ; i < q ; i ++)
		cin >> v[i] >> d[i] >> c[i] , v[i] --;
	return;
} 
int32_t main()
{
	input();
	for(int i = q - 1 ; i >= 0 ; i --)
		dfs(v[i] , d[i] , c[i]);
	for(int i = 0 ; i < n; i ++)
		cout << co[0][i] << endl;
	return 0;
}


Measured memory_bytes: 20724
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		long A[]=new long[N];
		long B[]=new long[N];
		int z=0;
		long sum=0,y=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			B[z]=stdIn.nextInt();
			z++;
		}z--;
		while(z>=0) {
			A[z]+=sum;
			while(true) {
				if(A[z]%B[z]==0)
					break;
				y=A[z]/B[z]+1;
				sum+=y*B[z]-A[z];
				A[z]=y*B[z];
			}
			z--;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 87016
#include<iostream>
#include<vector>

#define Max 999999

int main(){
	bool is_prime[Max+1];
	for(int i=0;i<=Max;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=Max;i++){
		if(is_prime[i]){
			for(int j=i*2;j<=Max;j+=i)is_prime[j]=false;
		}
	}
	int n;
	while(std::cin>>n){
		int count=0;
		for(int i=2;i<=n;i++){
			if(is_prime[i])count++;
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  int a[H+1][W+1];
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> a[i][j];
    }
  }
  vector<int> y, x, _y, _x;
  int N = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (a[i][j]%2 == 1 && j < W) {
        a[i][j]--;
        y.push_back(i), x.push_back(j);
        a[i][j+1]++;
        _y.push_back(i), _x.push_back(j+1);
        N++;
      }
      if (a[i][j]%2 == 1 && j == W && i < H) {
        a[i][j]--;
        y.push_back(i), x.push_back(j);
        a[i+1][j]++;
        _y.push_back(i+1), _x.push_back(j);
        N++;
      }
    }
  }
  cout << N << endl;
  for (int i = 0; i < N; i++) {
    cout << y[i] << " " << x[i] << " " << _y[i] << " " <<  _x[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5220
#include <bits/stdc++.h>
int main() {
    int h1, a1, h2, a2;
    std::cin >> h1 >> a1 >> h2 >> a2;
    while (h1 > 0 && h2 > 0) {
        if (h1 > 0 && h2 > 0) {
            h2 -= a1;
            if (h1 > 0 && h2 > 0) {
                h1 -= a2;
            }
        }
    }
    std::cout << (h1 > 0 ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int p[100000];
string s[100000];
map<int, int> mp;
map<int, int>::iterator it;

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

	for (int i = 0; i < m; i++) {
		cin >> p[i] >> s[i];
	}

	int ok = 0, ng = 0;

	for (int i = 0; i < m; i++) {
		if (mp.find(p[i]) == mp.end() && s[i] == "AC") {
			ok++;
			mp[p[i]] = -1;
		}else if (mp[p[i]]!=-1 && s[i] == "AC") {
			ok++;
			ng += mp[p[i]];
			mp[p[i]] = -1;
		}
		else if(mp.find(p[i]) == mp.end()){
			mp[p[i]] = 1;
		}
		else if(mp[p[i]]!=-1){
			mp[p[i]]++;
		}
	}
	cout << ok << " " << ng << endl;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int x, a; cin >> x >> a;

    if(x < a) dunk(0);
    else dunk(10);
}

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

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

ll N,Ma,Mb;
ll A[50], B[50], C[50];

ll cost[450][450];
ll INF = 1e18;

int main(){
    cin >> N >> Ma >> Mb;
    for(int i=0;i<N;i++) cin >> A[i] >> B[i] >> C[i];
    for(int i=0;i<=400;i++){
        for(int j=0;j<=400;j++){
            cost[i][j] = INF;
        }
    }
    cost[0][0] = 0;
    for(int i=0;i<N;i++){
        for(int a=400;a>=0;a--){
            for(int b=400;b>=0;b--){
                if(cost[a][b] == INF) continue;
                cost[a+A[i]][b+B[i]] = min(cost[a+A[i]][b+B[i]], cost[a][b] + C[i]);
            }
        }
    }
    ll ans = INF;
    for(int n=1;n*Ma<=400 && n*Mb<=400;n++){
        ans = min(ans, cost[n*Ma][n*Mb]);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5012
class SegTree
    def update(k); @d[k] = @op.call(@d[2 * k], @d[2 * k + 1]); end

    def initialize(v, e, &op)
        @e = e
        @n = v.size
        @log = (@n - 1).bit_length
        @size = 1 << @log
        @op = op

        @d = Array.new(2 * @size, e) # vector

        @n.times{|i| @d[@size + i] = v[i]}
        (@size - 1).downto(1) {|i| update(i)}
    end

    def set(pos, x)
        pos += @size
        @d[pos] = x
        1.upto(@log) {|i| update(pos >> i)}
    end

    def get(pos); @d[pos + @size]; end

    def prod(l, r)
        sml = @e
        smr = @e
        l += @size
        r += @size

        while l < r
            (sml = @op.call(sml, @d[l]); l += 1) if l[0] == 1
            smr = @op.call(@d[r -= 1], smr) if r[0] == 1
            l >>= 1
            r >>= 1
        end
        @op.call(sml, smr)
    end

    def all_prod; @d[1]; end

    def max_right(l, &f)
        return @n if l == @n
        l += @size
        sm = @e

        loop do
            l >>= 1 while l[0] == 0
            if !f.call(@op.call(sm, @d[l]))
                while l < @size
                    l <<= 1
                    if f.call(@op.call(sm, @d[l]))
                        sm = @op.call(sm, @d[l])
                        l += 1
                    end
                end
                return l - @size
            end
            
            sm = @op.call(sm, @d[l])
            l += 1
            break if (l & -l) == l
        end

        return @n
    end
    
    def min_left(r, &f)
        return 0 if r == 0
        r += @size
        sm = @e

        loop do
            r -= 1
            r >>= 1 while r > 1 && r[0] == 1
            if !f.call(@op.call(@d[r], sm))
                while r < @size
                    r = 2 * r + 1
                    if f.call(@op.call(@d[r], sm))
                        sm = @op.call(@d[r], sm)
                        r -= 1
                    end
                end
                return r + 1 - @size
            end
            sm = @op.call(@d[r], sm)
            break if (r & -r) == r
        end

        return 0
    end
end

n, q = gets.split.map(&:to_i)
st = SegTree.new(gets.split.map(&:to_i), -1) {|ch1, ch2| ch1 > ch2 ? ch1 : ch2}

q.times do
    t, x, y = gets.split.map(&:to_i)
    
    if t == 1
        st.set(x-1, y)
    elsif t == 2
        puts st.prod(x-1, y)
    else
        puts st.max_right(x-1){|v| v < y} + 1
    end
end

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
ll mod = 1000000007;


int main(){
    ll n,m;
    cin >> n >> m;
    if(n != 0) n = n * (n - 1) / 2;
    if(m != 0) m = m * (m - 1) / 2;
    cout << n + m << endl;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b;

main() {
    cin >> a >> b;
    if (a==1) a = 14;
    if (b==1) b = 14;
    if (a>b) ct("Alice")
    else if (a<b) ct("Bob")
    else ct("Draw")
}




Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int H,W,i=1,j=1;
    while(1){
        scanf("%d%d",&H,&W);
        if(H==0&&W==0)break;
        while(H>=i){
            while(W>=j){
                if(i==1||i==H||j==1||j==W)printf("#");
                else{
                    printf(".");
                }
                j++;
            }
            printf("\n");
            j=1;
            i++;
        }
        i=1;
        printf("\n");
    }
    return 0;
}

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

using ll = long long;

int main() {
    int N, K, a;
    cin >> N >> K;
    vector<ll> s(N + 1, 0), v;
    rep(i, N) {
        cin >> a;
        s[i + 1] = s[i] + a;
    }
    rep(i, N) {
        for (int j = i + 1; j <= N; j++) {
            v.push_back(s[j] - s[i]);
        }
    }
    for (int i = 59; i >= 0; i--) {
        int c = 0;
        rep(j, v.size()) {
            if (v[j] & (1LL << i)) c++;
        }
        if (c < K) {
            rep(j, v.size()) v[j] = (v[j] | (1LL << i)) ^ (1LL << i); 
        } else {
            rep(j, v.size()) {
                if ((v[j] & (1LL << i)) == 0) v[j] = 0;
            }
        }
    }
    sort(v.begin(), v.end());
    /*
    rep(i, v.size()) {
        cout << v[i] << "\n";
    }
    */
    ll ans = v[v.size() - 1];
    rep(i, K) {
        ans = ans & v[v.size() - 1 - i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 6260
/*  ex5_3
    Graku   */
#include<stdio.h>

int main(void) {
    int height, width;
    scanf("%d %d", &height, &width);
    int blank_rows[height], blank_cols[width]; //blank -> 0, not blank -> 1
    char matrix[height][width];
    for (int row = 0; row < height; ++row) {
        for (int col = 0; col < width; ++col) {
            scanf(" %c", &matrix[row][col]); //don't read "\n"
        }
    }

    for (int row = 0; row < height; ++row) { //find blank rows
        int flag = 0;
        for (int col = 0; col < width; ++col) {
            if ('#' == matrix[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_rows[row] = flag;
    }
    for (int col = 0; col < width; ++col) { //find blank columns
        int flag = 0;
        for (int row = 0; row < height; ++row) {
            if ('#' == matrix[row][col]) { //not blank
                flag = 1;
                break;
            }
        }
        blank_cols[col] = flag;
    }

    for (int row = 0; row < height; row++) {
        if (blank_rows[row]) { //if row is not blank
            for (int col = 0; col < width; ++col) {
                if (blank_cols[col]) { //if column is not blank
                    printf("%c", matrix[row][col]);
                }
            }
            printf("\n");
        }
    }

    return 0;
}

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

const int Maxn = 100005;

int n;
int a[Maxn];
vector <int> un;
int res;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        un.push_back(a[i]);
    }
    sort(un.begin(), un.end());
    for (int i = 1; i < n; i += 2) {
        int ind = lower_bound(un.begin(), un.end(), a[i]) - un.begin();
        if (ind % 2 == 0) res++;
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 1148
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int A = sc.nextInt();
     int B = sc.nextInt();
     int ans;
     if(A>=13){
      ans = B;
    }else if(A>=6){
      ans = B/2;
    }else{
      ans = 0;
    }

     System.out.println(ans);

   }
}


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

using namespace std;

typedef long long ll;

ll a[100005];
ll tmp[100005];
ll n,m,v,p;
int j;
bool check(int x) {
  ll ma = 0;
  ll sum = 0;
  for(int i = 0; i < j; i++) {
    if(i < p-v-1) {
      ma = max(ma,m);
    }
    else {
    ma = max(tmp[i] - x,ma);
    sum += max(tmp[i] - x,0ll);
    }
  }
  if(ma <= m && sum <= m * (n-v)) return true;
  else return false;
}

int main() {
 
  cin >> n >> m >> v >> p;
  for(int i = 0; i < n; i++) cin >> a[i];

  sort(a,a+n,greater<int> ());
  
  if(n - v < n-p+1) {
    j = 0;
  for(int i = p-1; i < n; i++) tmp[j++] = a[i];
  }
  else {
    j = 0;
    for(int i = v; i < n; i++) tmp[j++] = a[i];
  }

  // for(int i = 0; i < j; i++) cout << tmp[i] << endl;

  int l = -1, r = tmp[0];
  while(r - l > 1) {
    int mid = (l + r) / 2;
    //  cout << mid << endl;
    if(check(mid)) r = mid;
    else l = mid;
  }
  int ans = 0;
  int k = 0;
  //  cout <<"r = "<< r << endl;
  while(k < n && a[k] >= r) {
    ans++;
    k++;
  }
  cout << ans << endl;
}
  


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

A_even = A[0:N:2]
A_odd = A[1:N:2]

X = []
if N % 2 == 1:
    X.append(sum(A_even) - sum(A_odd))
else:
    X.append(sum(A_even) - sum(A_odd))
for i in range(1, N):
    X.append(2*A[i-1] - X[i-1])
    
print(*X)

Measured memory_bytes: 14488
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

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

    vector<ll> t_vec(N+1,-MOD*MOD);
    vector<ll> rest(0);

    for(int i=0; i<N; i++){
        ll t, d;
        cin >> t >> d;
        t--;
        if(t_vec[t]<d){
            rest.push_back(t_vec[t]);
            t_vec[t]=d;
        }else{
            rest.push_back(d);
        }
    }
    sort(t_vec.rbegin(), t_vec.rend());
    sort(rest.rbegin(), rest.rend());

    for(int i=0; i<N; i++){
        t_vec[i]+=(ll) 2*i+1;
    }

    //cout_vec(t_vec);

    ll ans = 0;
    int j=0;int k=0;    
    for(int i=0; i<K; i++){
        if(t_vec[j]>=rest[k]){
            ans+=t_vec[j];
            j++;
        }else{
            ans+=rest[k];
            k++;
        }
    }

    ll tmp=0;
    j=0;
    for(int i=0; i<K; i++){
        if(t_vec[i]>0){
            tmp+=t_vec[i];
        }else{
            tmp+=rest[j];
            j++;
        }
    }

    cout << max(tmp, ans) << endl;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
const int MN = 100012;
int n,m,dp[MN],ind[MN];
vector<int> g[MN];
int dfs (int u) {
    if (dp[u] > -1) return dp[u];
    for (int v : g[u])
        dp[u] = max(dp[u], 1+dfs(v));
    return dp[u] = max(dp[u],0);
}
int main (void) {
    memset(dp,-1,sizeof(dp));
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u,v; cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        ind[v]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (ind[i] == 0) {
           ans = max(ans, dfs(i));
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 9600
N,K = map(int,input().rstrip().split(" "))
P = list(map(int,input().rstrip().split(" ")))
C = list(map(int,input().rstrip().split(" ")))

ans = -(10 ** 15)
for i in range(N):
    kans = 0
    score = [0]
    nex = P[i] -1
    while True:
        score.append(score[-1] + C[nex])
        nex = P[nex] - 1
        if nex == P[i] -1:
            break;

    if score[-1] > 0:
        if score[1:(K % (len(score) -1)) + 1] != []:
            kans = score[-1] * (K // (len(score) -1)) + max(score[1:(K % (len(score) -1)) + 1])
        else:
            kans = score[-1] * ((K // (len(score) -1)) - 1) + max(score)
    else:
        if score[1:min(len(score) - 1,K) + 1] != []:
            kans = max(score[1:min(len(score) - 1,K) + 1])
        else:
            kans = -(10 ** 15)
    ans = max(ans,kans)
print(ans)

Measured memory_bytes: 80740
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(W + 1):
        if j - w[i] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])

Measured memory_bytes: 120684
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    if N == 2:
        print(abs(A[1] - A[0]))
        sys.exit()

    t = list(accumulate(A, add))
    r = list(accumulate(reversed(A), add))

    ans = INF
    for i in range(N-2):
        ans = min(ans, abs(t[i] - r[-2-i]))

    print(ans)


if __name__ == '__main__':
    main()


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

#define MAXN 200*1000 + 5

typedef long long ll;

const int mod = 1000*1000*1000 + 7;

vector<int> g[MAXN], adj[MAXN];
int sz[MAXN], n;

void add_self(int& a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}

void sub_self(int& a, int b) {
	a -= b;
	if(a < 0) a += mod;
}

int mul(int a, int b) {
	return ll(a) * ll(b) % mod;
}

int mpow(int a, int m) {
	if(m == 0) return 1;
	int x = mpow(a, m/2);
	x = mul(x, x);
	if(m % 2 == 1) x = mul(x, a);
	return x;
}

int divide(int a, int b) {
	return mul(a, mpow(b, mod-2));
}

void dfs(int u, int p = -1) {
	sz[u] = 1;
	for(int v : g[u]) {
		if(v != p) {
			dfs(v, u);
			add_self(sz[u], sz[v]);
			adj[u].push_back(sz[v]);
		}
	}
	
	if(p != -1)	
		adj[u].push_back(n-sz[u]);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	for(int rep = 0; rep < n - 1; rep++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	dfs(1);
	int ans = 0;
	
	for(int i = 1; i <= n; i++) {
		if((int) adj[i].size() < 2) continue;
		int none = 1;
		for(int j : adj[i]) {
			none = mul(none, mpow(divide(1, 2), j));
		}
		int one = 0;
		for(int j : adj[i]) {
			int x = mul(none, mpow(2, j));
			int z = 1;
			sub_self(z, mpow(divide(1, 2), j));
			x = mul(x, z);
			add_self(one, x);
		}
		
		int contrib = 1;
		sub_self(contrib, none);
		sub_self(contrib, one); // need at least 2 black nodes
		contrib = divide(contrib, 2); // node must be white
		add_self(ans, contrib);
	}

	cout << ans << endl;
}


Measured memory_bytes: 36224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String n = scan.next();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int nI = Integer.parseInt(n);




		int sum = 0;
		for(int i=1;i<=nI;i++) {
			int keta = 0;
			String iS = String.valueOf(i);
			for(int l=0;l<iS.length();l++) {
				char ketaC[] = new char[iS.length()];
				ketaC[l]=iS.charAt(l);
				keta = keta + Character.getNumericValue(ketaC[l]);
				}
			//各桁の合計＝keta
			if(keta>=a && keta<=b) {
				sum = sum + i;
			}
		}
		System.out.println(sum);
		}
	}




Measured memory_bytes: 23892
use std::io;
use std::io::{BufRead, Write};


fn sqrt(a_nInput: usize) -> usize
{
    let mut op  = a_nInput;
    let mut res = 0;
    let mut one = 1 << 62; // The second-to-top bit is set: use 1u << 14 for uint16_t type; use 1uL<<30 for uint32_t type

    // "one" starts at the highest power of four <= than the argument.
    while (one > op)
    {
        one >>= 2;
    }

    while (one != 0)
    {
        if (op >= res + one)
        {
            op = op - (res + one);
            res = res +  2 * one;
        }
        res >>= 1;
        one >>= 2;
    }
    return res;
}
fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let q: usize = buf.trim_right().parse().unwrap();
    for _ in 0..q {
        buf.clear();
        input.read_line(&mut buf).unwrap();
        let (a, b): (usize, usize) = {
            let mut split = buf.split_whitespace();
            (
                split.next().unwrap().parse().unwrap(),
                split.next().unwrap().parse().unwrap(),
            )
        };
        let max_product = a * b - 1;
        if max_product == 0 {
            writeln!(output, "0").unwrap();
            continue;
        }
        let root = sqrt(max_product);
        let alt_root = max_product / root;
        let left_candidate = (root, if alt_root == b { root } else { alt_root });
        let right_candidate = (if alt_root == a { root } else { alt_root }, root);
        let mut disabled = 0;
        let mut collision = false;
        if left_candidate.0 == a || left_candidate.1 == b {
            disabled += 1;
            collision = true;
        } else if a < root {
            disabled += 1;
        }
        if right_candidate.0 == a || right_candidate.1 == b {
            disabled += 1;
            collision = true;
        } else if b < root {
            disabled += 1;
        }
        if !collision && left_candidate == right_candidate {
            disabled += 1;
        }
        writeln!(output, "{}", root * 2 - disabled).unwrap();
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323
",
            "1
12
4
11
14
57
31
671644785
",
        );
    }

        #[test]
    fn case2() {
        test(
            "1
1 1
",
            "0
",
        );
    }
}


Measured memory_bytes: 4352
#include <iostream>

void call(int n){
  int i = 1;
  int x;
  do{
      x = i;
      if(x % 3 == 0) printf(" %d", i);
      else{
          do{
              if(x % 10 == 3){ printf(" %d", i); break;}
              else x /= 10; 
          } while(x) ;
      }
  } while(++i <= n);
  putchar('\n');
}

int main(void){
    int n; scanf("%d", &n);
    call(n);
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int M = sc.nextInt();
			int T = sc.nextInt();
			int P = sc.nextInt();
			int R = sc.nextInt();
			if (M == 0)
				break;
			Team[] team = new Team[T];
			for (int i = 0; i < T; i++) {
				team[i] = new Team(i + 1, P);
			}
			for (int i = 0; i < R; i++) {
				int m = sc.nextInt();
				int t = sc.nextInt();
				int p = sc.nextInt();
				int j = sc.nextInt();
				if (j == 0) {
					team[t - 1].judge_true(p, m);
				} else {
					team[t - 1].judge_false(p);
				}
			}
			Arrays.sort(team);
			int prev_answer = -1;
			int prev_time = 0;
			for (Team t : team) {
				if (prev_answer == t.answer && prev_time == t.time)
					System.out.print("=");
				else if (prev_answer != -1)
					System.out.print(",");
				System.out.print(t.t);
				prev_answer = t.answer;
				prev_time = t.time;
			}
			System.out.println("");
		}
	}
}

class Team implements Comparable<Team> {
	int t;
	int p[];
	int time;
	int answer;

	Team(int t, int P) {
		this.answer = 0;
		this.time = 0;
		this.t = t;
		this.p = new int[P];
	}

	void judge_false(int no) {
		p[no - 1] += 20;
	}

	void judge_true(int no, int m) {
		time += m + p[no - 1];
		answer++;
	}

	@Override
	public int compareTo(Team o) {
		if (answer == o.answer) {
			if (time == o.time) {
				if (t == o.t)
					return 0;
				else if (t < o.t)
					return 1;
				else
					return -1;
			} else if (time > o.time)
				return 1;
			else
				return -1;
		} else if (answer < o.answer)
			return 1;
		else
			return -1;
	}
}

Measured memory_bytes: 60876