akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		double x, y;
		int n;

		n = sc.nextInt();
		while (n != -1) {
			x = 1.0;
			y = 0.0;

			for (int i = 0; i < n - 1; i++) {
				if (x == 0.0) {
					if (0 < y) {
						x -= 1.0;
					} else {
						x += 1.0;
					}
				} else if (y == 0.0) {
					if (0 < x) {
						y += 1.0;
					} else {
						y -= 1.0;
					}
				} else {
					double theta = Math.atan2(y, x) + Math.PI / 2;
					x += Math.cos(theta);
					y += Math.sin(theta);
				}
			}
			System.out.println(x);
			System.out.println(y);
			n = sc.nextInt();
		}		
	}
}

Measured memory_bytes: 12000
#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 REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
	int N,K;
	string S;
	cin >>N >> K;
	cin >>S;
	S[K-1] = (char)(toupper(S[K-1])+32); 
	cout << S <<endl;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> B(N-1);
	for (int n = 0; n <N-1; ++n) {
		cin >> B[n];
	}
	int ans = 0;	
	for (int n = 0; n < N - 2; ++n) {
		ans += min(B[n],B[n+1]);
	}
	ans += B[0];
	ans += B[N - 2];
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 3596
while True:
	H,W=map(int,input().split())
	if H==0 and W==0:
		break
	for j in range(H):
		if j%2==0:
			for i in range(W):
				if i%2==0:
					print("#", end="")
				else:
					if j%2==0:
						print(".", end="")
		else:
			for i in range(W):
				if i%2==0:
					print(".", end="")
				else:
						print("#", end="")
		print()
	print()



Measured memory_bytes: 7004
#include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    using namespace std;
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
     
        int h, w, d;
        cin >> h >> w >> d;
     
        char c[502];
        c[w] = '\n';
        c[w + 1] = 0;
     
        for (int i = 0; i < h; i++) {
            int x = h - i + d - h % d;
            for (int j = 0; j < w; j++) {
                c[j] = "YBGR"[(i + j) / d % 2 + (x + j) / d % 2 * 2];
            }
            cout << c;
        }
     
        return 0;
    }

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2000;
vector<int> G[MAXN * 2]; //1 ~ 2N - 1
int height[MAXN * 2], depth[MAXN * 2];
void build(int u, int p, int d) {
    int h = 0;
    for (int v : G[u]) {
        if (v == p) continue;
        build(v, u, d + 1);
        h = max(h, height[v] + 1);
    }
    height[u] = h, depth[u] = d;
}
int uAsCenter(int N, int K, int u) {
    if (G[u].size() == 1) return N - 1;
    vector<int> vh;
    build(u, -1, 0);
    transform(G[u].begin(), G[u].end(), back_inserter<decltype(vh)>(vh), [](int v) {
        return height[v] + 1;
    });
    nth_element(vh.begin(), vh.begin() + 1, vh.end(), greater<int>());
    int _K = min(K, vh[1]);
    return count_if(depth + 1, depth + N + 1, [_K](int d) {
        return d > _K;
    });
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    for (int i = 1; i < N; i++) {
        int u, v, w = N + i;
        cin >> u >> v;
        G[u].push_back(w), G[w].push_back(v);
        G[v].push_back(w), G[w].push_back(u);
    }
    int ans = N - 1;
    for (int i = 1; i < 2 * N; i++) {
        ans = min(ans, uAsCenter(N, K, i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int a[1001],ta[1001],tta[1001];
int dp[1000021],dp2[1000010];
const int INF=99999999;
int main(){
	a[1]=1,ta[1]=1,tta[1]=1;
	int cnt=1;
	for(int i=2;i<=1000;i++)a[i]=i+a[i-1];
	for(int i=2;i<=1000;i++){
	ta[i]=a[i]+ta[i-1];
	if(ta[i]%2==1)tta[++cnt]=ta[i];
	}

	fill(dp,dp+1000001,INF);
	fill(dp2,dp2+1000001,INF);
	dp[0]=0,dp2[0]=0;
	for(int i=1;i<=200;i++){
		for(int j=1;j<=1000000;j++){
		if(j>=ta[i])dp[j]=min(dp[j],dp[j-ta[i]]+1);
		}//
	}//endfor
	for(int i=1;i<=100;i++){
		for(int j=1;j<=1000000;j++){
		if(j>=tta[i])dp2[j]=min(dp2[j],dp2[j-tta[i]]+1);
		}
	}//endfor
	int n;
	while(true){
	scanf("%d",&n);
	if(n==0)break;
	cout<<dp[n]<<" "<<dp2[n]<<endl;
	}//endwhile
	return 0;
}

Measured memory_bytes: 9032
import sys
input = sys.stdin.readline

# K+1 - x でうつす -> i と 2K+2-i は同じ

MOD = 998244353
U = 10000
fact = [1] * (U+1)
fact_inv = [1] * (U+1)
for n in range(1,U+1):
    fact[n] = fact[n-1] * n % MOD
fact_inv[n] = pow(fact[n], MOD-2, MOD)
for n in range(U,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD

def comb(n,k):
    if not (0 <= k <= n):
        return 0
    return fact[n] * fact_inv[k] * fact_inv[n-k] % MOD

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

def F(x,y,N):
    n = min(x, N)
    return sum(comb(x,i) * pow(2,i,MOD) * comb(N+y-1,i+y-1) % MOD for i in range(n+1)) % MOD

answer = []
for S in range(3,K+3,2):
    x = F((S-1)//2, K - S + 1, N)
    answer.append(x)
    answer.append(x)

if K & 1:
    answer = answer[:-1]
    answer += answer[:-1][::-1]
else:
    answer += answer[:-1][::-1]    

print('\n'.join(map(str,answer)))



Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define p push
#define ll long long 
#define mod 1000000007
#define mk make_pair

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int h,n;
   cin>>h>>n;
   int dp[h+1]={0};
   for(int i=1;i<=h;i++)
   dp[i]=INT_MAX;
   vector<pair<int,int>> v;
   v.resize(n);int a,b;
   for(int i=0;i<n;i++)
   {cin>>a>>b;v[i].first=a;v[i].second=b;}
   for(int i=1;i<=h;i++)
   {
       for(int j=0;j<n;j++)
       {
           if(i>v[j].first)
           dp[i]=min(dp[i-v[j].first]+v[j].second,dp[i]);
           else 
           {
               dp[i]=min(v[j].second,dp[i]);
           }
       }
   }
   //for(int i=0;i<177;i++)
   cout<<dp[h];
   return 0; 
}


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

using namespace std;

int main(){

    map<char, int> check1, check2;

    string s, t;

    cin >> s >> t;

    for( int i = 0; i < s.size(); i++){
        check1[s[i]] ++;
        check2[t[i]] ++;
    }

    vector <int> ss;
    vector <int> tt;

    for( auto i : check1){
        ss.push_back(i.second);
    }

    for( auto i : check2){
        tt.push_back(i.second);
    }

    sort(ss.begin(), ss.end());
    sort(tt.begin(), tt.end());

    if( ss.size() != tt.size()){
        cout << "No";
        return 0;
    }

    for( int i = 0; i < ss.size(); i++){
        if( ss[i] != tt[i] ){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";
    return 0;
}


Measured memory_bytes: 776
<?php
//error_reporting(0);
$S = trim(fgets(STDIN));
//list($n,$m,$d) = explode(" ",trim(fgets(STDIN)));
//$a = explode(" ",trim(fgets(STDIN)));

if ($S[0]!='A') {
  printf("WA\n");
  exit;
}
$len = strlen($S);
if ($S[1]=='C'||$S[$len-1]=='C') {
  printf("WA\n");
  exit;
}
$c = substr($S,2,$len-(2+1));
if (substr_count($c,"C")>1) {
  printf("WA\n");
  exit;
}
if (substr_count($S,"C")==0) {
  printf("WA\n");
  exit;
}
$new = str_replace(array("A","C"),array("",""),$S);
if ($new == strtolower($new)) {
  printf("AC\n");
}
else {
  printf("WA\n");
}


Measured memory_bytes: 3828
def sol(inp=input):
    res=0
    h,w=map(int,inp().split())
    vers=[None for _ in range(w)]
    atlas=[list(inp()+'#') for _ in range(h)]+[['#']*(w+1)]
    for i in range(h):
        hol=None
        for j in range(w):
            if atlas[i][j]=='.':
                if hol is None:
                    for j_ in range(j,w+1):
                        if atlas[i][j_]=='#':
                            hol=j_-j
                            break
                if vers[j] is None:
                    for i_ in range(i,h+1):
                        if atlas[i_][j]=='#':
                            vers[j]=i_-i
                            break
                res=max(res,hol+vers[j]-1)
            else:
                hol=None
                vers[j]=None
    return '{}'.format(res) 
print(sol())

Measured memory_bytes: 184968
#include <string.h>
#include <ctype.h>
#include <stdio.h>
int main(void){
    char W[10];
    char T[1000];
    char end[100]="END_OF_TEXT";
    int i,cnt=0;
    
    scanf("%s",W);
    for(i=0; i<strlen(W); i++){
        W[i]=tolower(W[i]);
    }
    
    while(1){
        scanf("%s",T);
        if(strcmp(T,end) == 0) break;
        //strcmp(str1,str2)(?????????<string.h>)?????????str1??¨str2???????????????????????????????????????????????§?°??????????????????????str1???????????§????????¨??£????°?????????¨?????????????????¨0????????????
        
        for(i=0; i<strlen(T); i++){
            T[i]=tolower(T[i]);
        }
        
        if(strcmp(T,W) == 0) cnt++;
    }
    
    printf("%d\n",cnt);
    
    return 0;
}

Measured memory_bytes: 552
n = int(input())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

ans = 0
for i in range(n - 1, -1, -1):
    ans += (b[i] - (a[i] + ans) % b[i]) % b[i]

print(ans)

Measured memory_bytes: 11096
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    int a, b;
    cin >> a >> b;
    cout << ((a * 3 + b) / 2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,dp[3097152][23],a[25][25],md=1e9+7;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
                scanf("%d",&a[i][j]);
        }

    }
    for (int i=0;i<n;i++)
    {
        if (a[0][i]==1) dp[1<<i][0]=1;
    }
    for (int j=1;j<n;j++)
    {
        for (int k=0;k<(1<<n)-1 ;k++)
        {
            if (dp[k][j-1]==0) continue;
            for (int i=0;i<n;i++)
            {
                if (a[j][i]==0) continue;
                if ((k&(1<<i))!=0) continue;
                int x=k|(1<<i);
                dp[x][j]+=dp[k][j-1]%md;
                dp[x][j]%=md;
            }
        }
    }
    cout<<dp[(1<<n)-1][n-1];
}


Measured memory_bytes: 190720
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
	static double s;
	
    public static void main(String[] args)   throws Exception, IOException{        
//        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n=sc.nextInt();
        long t=sc.nextLong();
        long tt=sc.nextLong();
        long a=sc.nextLong();
        long aa=sc.nextLong();
        long b=sc.nextLong();
        long bb=sc.nextLong();
        long s=(b-a)*t+(bb-aa)*tt;
        if(t*a+tt*aa==t*b+tt*bb) {
        	ret("infinity");
        }
        long r=0,rr;
        r=t*(a-b)/s;
        if(r<0)r=0;

        rr=(tt*(aa-bb)+t*(a-b))/s;
        if(rr<0) {
        	rr=t*(a-b)/s;
        	if(rr<0)rr=0;
        	else rr=(long)ceil((double)t*(a-b)/s);
        }
        
        out.println(r+rr);
     	out.flush();
    }


    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//
//class P {
//	int x, y, d;
//	P(int  x, int y, int d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}

class P implements Comparable<P>{
    int a,b;
    P(int a, int b) {
    	this.b=b;
    	this.a=a;
    }

    public int compareTo(P p){
        return -p.a+a;//as
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

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

    vector<int> a(n);
    vector<P> cb(m);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < m; i++)
        cin >> cb[i].second >> cb[i].first;

    sort(a.begin(), a.end());
    sort(cb.begin(), cb.end());
    reverse(cb.begin(), cb.end());

    // min(a)をmax(c)と取り替えようとする
    int i_cb = 0;
    for(int i = 0; i < n && i_cb < m; i++) {
        if(a[i] < cb[i_cb].first) {
            a[i] = cb[i_cb].first;
            cb[i_cb].second--;
        }
        if(cb[i_cb].second <= 0)
            i_cb++;
    }

    cout << accumulate(a.begin(), a.end(), 0LL) << endl;
}

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

int main() {
  int N;
  cin >> N;
  int B = 0;
  vector<int> weights(N);
  for (int i = 0; i < N; i++) {
    cin >> weights[i];
    B += weights[i];
  }
  int A = 0;
  for (int i = 0; i < N; i++) {
      A += weights[i];
      B -= weights[i];
    if (A >= B) {
      cout << min(A - B, B + 2 * weights[i] - A) << endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


struct P
{
	int name, point;
};

void input(vector<vint>& v)
{
	rep(i, 10)
	{
		int f;
		cin >> f;
		  
		v[i][0] = f;
		
		// 2Úª éê
		if(f != 10 || i == 9)
		{
			int s;
			cin >> s;
			
			v[i][1] = s;
		}
	}
	
	// 10t[ÚÌÅãÌ
	if(v[9][0] + v[9][1] == 10 || v[9][1] == 10 || v[9][0] == 10)
	{
		int l;
		cin >> l;
		
		v[9][2] = l;
	}
}

int calc(vector<vint> v)
{
	// Åã©çßÄ¢­
	// 10t[ÚÌÝÊ

	int res = v[9][0] + v[9][1] + (v[9][2] != -1 ? v[9][2] : 0);
	
	rep(i, 9)
	{
		if(v[i][0] == 10)
		{
			res += 10 + v[i + 1][0] + (v[i + 1][1] != -1 ? v[i + 1][1] : (i < 8 ? v[i + 2][0] : v[i + 1][2]));
		}
		else if(v[i][0] + v[i][1] == 10)
		{
			res += 10 + v[i + 1][0];
		}
		else res += v[i][0] + v[i][1];
	}
	
	return res;
}

bool pred(P a, P b)
{
	return a.point > b.point || (a.point == b.point && a.name < b.name);
}

int main()
{
    int n;
	while(cin >> n && n)
	{
		vector<P> pnt(n);
		
		rep(i, n)
		{
			cin >> pnt[i].name;

			vector<vint> v(10, vint(3, -1));
			
			// üÍðó¯æé
			input(v);
			
			// ¾_ðvZ·é
			pnt[i].point = calc(v);
		}
		
		// å«¢Å\[g
		sort(ALL(pnt), pred);
		
		rep(i, n)
			cout << pnt[i].name << " " << pnt[i].point << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
long long int x[200000],y[200000],z[200000],w[200000];
int main(){
  int n,i;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>x[i]>>y[i];
    z[i]=x[i]+y[i];
    w[i]=x[i]-y[i];
    }
  sort(z,z+n)
   ;
  sort(w,w+n);
  cout<<max(z[n-1]-z[0],w[n-1]-w[0])<<endl;
  return 0;
  }


Measured memory_bytes: 9876
n, m = map(int,input().split())
a = {}
for i in range(1,n+1):
    a[i] = [0,0]
for i in range(m):
    p, s = input().split()
    p  = int(p)
    if a[p][1] == 0 and s == "WA":
        a[p][0] += 1
    elif s == "AC" and a[p][1] == 0:
        a[p][1] = 1
ac = 0
wa = 0
for i in range(1,n+1):
    if a[i][1] == 1:
        wa += a[i][0]
    ac += a[i][1]
print(ac,wa)

Measured memory_bytes: 23204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,m; cin >> n >> m;
  vi a(n);
  priority_queue<int> pq;
  rep(i,n ){
    int foo; cin >> foo;
    pq.push(foo); 
  }
  rep(i,m) {
    int foo = pq.top(); pq.pop();
    foo >>= 1;
    pq.push(foo);
  }
  ll ans = 0;
  rep(i, n) {
    ans+=pq.top(); pq.pop();
  }
  printf("%lld\n", ans);
  return 0;

}

Measured memory_bytes: 1276
#include <cstdio>
#include <cstring>
#define MAXN 1000010
#define MAXD 21

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n;
int g[MAXN],nume;
int f[MAXN][MAXD];

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void dfs(int x,int p){
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p)
			dfs(e[i].to,x);
	static int cnt[MAXD];
	memset(cnt,0,sizeof cnt);
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p)
			for(int j=0;j<MAXD;j++)
				if(f[e[i].to][j])
					cnt[j]++;
	int pos=MAXD-1;
	while(pos>=0 && cnt[pos]<=1) pos--;
	while(cnt[++pos]);
	f[x][pos]=1;
	for(int i=pos+1;i<MAXD;i++)
		f[x][i]=cnt[i];
}

int main(){
#ifdef DEBUG
	freopen("D.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	dfs(1,0);
	for(int i=MAXD-1;i>=0;i--)
		if(f[1][i]){
			printf("%d\n",i);
			return 0;
		}
	return 0;
}


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

int main(){
 string S, T;
 cin >> S >> T;
 int A, B;
 cin >> A >> B;
 string U;
 cin >> U;
 if(U == S){
  cout << A - 1 << " " << B << endl;
 }   
 else if(U == T){
  cout << A << " " << B - 1 << endl;
 }
}

Measured memory_bytes: 256
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (N) = readInts()
    val a = readInts()

    val twos = a.filter { it % 2 == 0 && it % 4 != 0 }.count()
    val fours = a.filter { it % 4 == 0 }.count()
    val others = a.filter { it % 2 != 0 }.count()

    println(if (fours + 1 - others - (twos % 2) >= 0) "Yes" else "No")
}

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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
void dump_vec(const vector<T> &v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

template <class T>
int insertion_sort(vector<T> &A, const int n, const int g) {
    int cnt = 0;
    rep(i, g, n) {
        auto v = A[i];
        auto j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j        = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
    return cnt;
}

template <class T>
void shell_sort(vector<T> &A, int n) {
    vector<int> G;
    auto gap = n - 1;
    while (gap > 1) {
        G.push_back(gap);
        gap /= 2;
    }
    G.push_back(1);

    const auto m = G.size();
    cout << m << "\n";
    dump_vec(G);

    int cnt = 0;
    rep(i, 0, m) {
        cnt += insertion_sort(A, n, G[i]);
    }
    cout << cnt << "\n";
}

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) {
        cin >> A[i];
    }
    shell_sort(A, N);
    rep(i, 0, N) {
        cout << A[i] << "\n";
    }
}



Measured memory_bytes: 6712
#include <bits/stdc++.h>
using namespace std;
using PP = pair<int, int>;

const long mod = 998244353;
int n;
PP p[200000];

bool inter(int i, int j) {
  return p[i].first + p[i].second > p[j].first;
}

long rec(int begin, int& end) {
  long prod = 1;
  int curr = begin + 1;
  while (curr < n && inter(begin, curr)) {
    int next;
    long res = rec(curr, next);
    prod = prod * res % mod;
    curr = next;
  }
  end = curr;
  return (prod + 1) % mod;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;
  sort(p, p + n);
  
  long prod = 1;
  int curr = 0;
  while (curr < n) {
    int next;
    long res = rec(curr, next);
    prod = prod * res % mod;
    curr = next;
  }
  cout << prod << endl;
}


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int a, b, c, d;
    a = n / 1000;
    b = n / 100 - a * 10;
    c = n / 10 - a * 100 - b * 10;
    d = n - a * 1000 - b * 100 - c * 10;
    int op1[8] = {1, 1, 1, 1, -1, -1, -1, -1};
    int op2[8] = {1, 1, -1, -1, 1, 1, -1, -1};
    int op3[8] = {1, -1, 1, -1, 1, -1, 1, -1};
    char ans1 = '+';
    char ans2 = '+';
    char ans3 = '+';
    for (int i = 0; i < 8; ++i)
    {
        int cal = a + b * op1[i] + c * op2[i] + d * op3[i];
        if (cal == 7)
        {
            if (op1[i] == -1)
            {
                ans1 = '-';
            }
            if (op2[i] == -1)
            {
                ans2 = '-';
            }
            if (op3[i] == -1)
            {
                ans3 = '-';
            }
            break;
        }
    }
    cout << a << ans1 << b << ans2 << c << ans3 << d << "=7" << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
const int maxn=2e5+5;
using namespace std;
int n,a[maxn];
ll ans,cnt[maxn];
inline int read() {
	char ch = getchar();
	int x = 0, f = 1;
	while (ch < '0' || ch > '9')
		f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - 48, ch = getchar();
	return x * f;
}
int main() {
	n=read();
	for(int i=1; i<=n; i++)
		a[i]=read(),cnt[a[i]]++;
	for(int i=1; i<=n; i++)
		if(cnt[i])
			ans+=cnt[i]*(cnt[i]-1)/2;
	for(int i=1; i<=n; i++) {
		printf("%lld\n",ans-cnt[a[i]]*(cnt[a[i]]-1)/2+(cnt[a[i]]-1)*(cnt[a[i]]-2)/2);
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    
    cin>>N;
    
    int arr[N];
    
    for(int i=0; i<N; i++)
    {
        cin>>arr[i];
    }
    
    double sum = 0;
    
    for(int i=0; i<N; i++)
    {
        sum+=(1.0/arr[i]);
    }
    
    cout<<1.0/sum<<endl;
    
    
}

Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val mod = 1000000007L
  val Array(n, w) = readLine.trim.split(' ').map(_.toInt)
  val friends = Array.tabulate(n){_ ⇒ readInt()}.sorted
  val sumWeights = 0 +: friends
  for (i ← sumWeights.indices.tail) sumWeights(i) += sumWeights(i - 1)
  var result = if (friends.sum <= w) 1L else 0L
  val memo = Array.fill(w + 1){0L}//memo(w) => (i, n]の友達の組み合わせで重さがwになるもの
  memo(0) = 1
  for (i ← (0 until n).reverse) {
    for (d ← ((w - friends(i) + 1) to w).map{_ - sumWeights(i)} if memo.indices.contains(d)) {
      result += memo(d)
    }
    result %= mod
    for (d ← (0 to w - friends(i)).reverse) {
      memo(d + friends(i)) += memo(d)
      memo(d + friends(i)) %= mod
    }
  }
  println(result)
}


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

const ll INF = 1LL << 60;
long long N;
long long M;
long long Q;
vector<ll> a, b, c, d;
ll ans = 0;

// i: 何回めか
// v: 配列
void dfs(int cnt, int i, vector<int> v) {
    if (cnt >= N) {
        // 操作
        // rep(k, v.size()) {
        //     cout << v[k] << " ";
        // }
        // cout << endl;
        ll tmp = 0;
        rep(k, Q) {
            ll diff = v[b[k]] - v[a[k]];
            if (diff == c[k]) {
                tmp += d[k];
            }
        }
        ans = max(ans, tmp);
        return;
    }
    v.push_back(i);
    for (int m = i; m <= M; m++) {
        dfs(cnt + 1, m, v);
    }
}

int main() {
    scanf("%lld",&N);
    scanf("%lld",&M);
    scanf("%lld",&Q);
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);

    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
        a[i]--;
        b[i]--;
    }

    // vector<int> tmp;
    // dfs(0, 1, tmp);
    // return 0;

    for (int i = 1; i <= M; i++) {
        vector<int> tmp;
        dfs(0, i, tmp);
    }

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


Measured memory_bytes: 3664
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,a,x;
    cin>>x>>a;
   i=(x<a)?0:10;
    cout<<i<<endl;




    return 0;
}





Measured memory_bytes: 3624
from fractions import gcd

A, B, C, D = map(int, input().split())

a = (B-A+1)
b = -(B//C + B//D - B//(C*D//gcd(C,D)))
c = ((A-1)//C + (A-1)//D - (A-1)//(C*D//gcd(C,D)))

print(a+b+c)

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

int main() {
  long double A, B, X;
  cin >> A >> B >> X;

  long double r;
  if (A * A * B / 2 < X) {
    long double a = A * A * B - X;
    long double b = a * 2 / (A * A);
    r = atan2(b, A);
  } else {
    long double a = X * 2 / (A * B);
    r = atan2(B, a);
  }

  cout << fixed << setprecision(50) << r * 180 / M_PI << "\n";
}

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

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    deque<int> dq;
    for(int i = 0; i < n; ++i){
        int id = lower_bound(dq.begin(), dq.end(), a[i]) - dq.begin();
        if(id == 0)     dq.push_front(a[i]);
        else            dq[id - 1] = a[i];
    }
    int ans = (int)dq.size();
    cout << ans << endl;
}

Measured memory_bytes: 1024
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<char> C(N);
	queue<int> R;
	queue<int> W;
	for (int i = 0; i < N; i++) {
		cin >> C.at(i);
		if (C.at(i) == 'R') R.push(1);
		else W.push(1);
	}

	long long cnt = 0;

	for (int i = 0; i < N; i++) {
		if (R.empty() || W.empty()) break;
		if (C.at(i) == 'R') R.pop();
		else if (C.at(i) == 'W') {
			W.pop();
			R.pop();
			cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 100000000

int dp[2][51][5001];

int main() {
	
	int N,K;
	cin>>N>>K;
	
	dp[0][0][2500] = 1;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=N;j++){
			for(int v=0;v<=5000;v++){
				if(dp[0][j][v]==0)continue;
				
				dp[1][j][v] = mod(dp[0][j][v] + dp[1][j][v]);
				
				if(j!=N){
					dp[1][j+1][v-2*(i+1)] = mod(dp[1][j+1][v-2*(i+1)] + dp[0][j][v]);
				}
				
				if(j!=0){
					dp[1][j-1][v+2*(i+1)] = mod(dp[1][j-1][v+2*(i+1)] + mod(j*j*dp[0][j][v]));
				}
				
				dp[1][j][v] = mod(dp[1][j][v] + mod(dp[0][j][v] * j*2));
			}
		}
		swap(dp[0],dp[1]);
		for(int j=0;j<=N;j++){
				for(int v=0;v<=5000;v++){
					dp[1][j][v]=0;
				}
		}
	}
	
	cout<<dp[0][0][K+2500]<<endl;
	
    return 0;
}


Measured memory_bytes: 2176
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) = tokiomarine2020c()

fun tokiomarine2020c() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }

    var curr = aList.toLongArray()

    repeat(min(k, 50)) {
        val imos = LongArray(n)

        curr.withIndex().map { (index, value) ->
            val left = max(index - value, 0)
            imos[left.toInt()]++

            val right = index + value + 1
            if (right in imos.indices) imos[right.toInt()]--
        }

        for (i in 0 until n - 1) imos[i + 1] += imos[i]

        curr = imos.copyOf()
    }

    val answer = curr.joinToString(" ")

    println(answer)
}


Measured memory_bytes: 102112
function main() {
  var
  inf = 10e9,
  line,
  n, m, a, b, c, t, p, q, r,
  i, j, k;
  
  while (true) {
    line = input.shift().split(' ').map(parseFloat);
    n = line[0]; m = line[1];
    if (n === 0 && m === 0) break;

    cost = []; time = [];
    for (i = 1; i <= m; i++) {
      cost[i] = []; cost[i][i] = 0;
      time[i] = []; time[i][i] = 0;
    }

    for (i = 0; i < n; i++) {
      line = input.shift().split(' ').map(parseFloat);
      a = line[0]; b = line[1]; c = line[2]; t = line[3];
      cost[a][b] = cost[b][a] = Math.min(c, cost[a][b]||inf);
      time[a][b] = time[b][a] = Math.min(t, time[a][b]||inf);
    }

    for (k = 1; k <= m; k++) {
      for (i = 1; i <= m; i++) {
        for (j = 1; j <= m; j++) {
          cost[i][j] = Math.min(cost[i][j]||inf,(cost[i][k]||inf)+(cost[k][j]||inf));
          time[i][j] = Math.min(time[i][j]||inf,(time[i][k]||inf)+(time[k][j]||inf));
        }
      }
    }

    k = parseFloat(input.shift());
    for (i = 0; i < k; i++) {
      line = input.shift().split(' ').map(parseFloat);
      p = line[0]; q = line[1]; r = line[2];
      console.log(p === q ? 0 : [cost,time][r][p][q]);
    }
  }
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 33984
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,cnt;
string s[2005];
int main()
{
	cin>>n;
	m=n;
    while(m)
    {
    cnt+=m%10;
    m/=10;
	}
	if(n%cnt)
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
	return 0;
    return 0;
	} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  long a[200000];
  bool bo[200000];
  for(int i=0;i<n;i++) {
    cin >> a[i];
    bo[i] = false;
  }
  int count = 0;
  sort(a,a+n);
  for(int i=n-1;i>0;i--){
    long t = 1;
    if(bo[i]) continue;
    while(t<=a[i]) t <<= 1;
    long dst = t - a[i];
    int b=0,e=i;
    while(b+1<e){
      int m = (b+e)/2;
      if(dst<a[m] || (dst==a[m]&&bo[m])) e=m;
      else b=m;
    }
    if(a[b]!=dst || bo[b]) continue;
    count ++;
    bo[b] = true;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 2048
import sys
N = int(input())
p_s = list(map(int,input().split()))
cnt = 0
for i,p in enumerate(p_s):
    if i+1 != p:
  	    cnt += 1
    if cnt > 2:
        break
else:
    print("YES")
    sys.exit(0)
print("NO")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
long long a[MAXN],b[MAXN],ans,n;
int main()
{
    cin >>n;    
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=b[i-1]+a[i];
        ans+=a[i];
    }
    long long cmin=INT_MAX;
    for(int i=1;i<n;i++)
        if(cmin>abs(2*b[i]-ans))
            cmin=abs(2*b[i]-ans);
    cout<<cmin<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int R, C, n;
	scanf("%d%d%d", &R, &C, &n);
	auto getId = [&](int x, int y) {
		if (y == 0) return x;
		if (x == R) return R + y;
		if (y == C) return R + C + (R - x);
		if (x == 0) return R + C + R + (C - y);
		return -1;
	};
	vector<pair<int, int>> st;
	for (int i = 0; i < n; ++i) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		int id1 = getId(x1, y1);
		int id2 = getId(x2, y2);
		if (id1 == -1 || id2 == -1) continue;
		if (id1 > id2) swap(id1, id2);
		st.push_back({id1, i});
		st.push_back({id2, i});
	}
	sort(st.begin(), st.end());
	stack<int> S;
	vector<bool> seen(n);
	for (auto& v : st) {
		if (!seen[v.second]) {
			seen[v.second] = true;
			S.push(v.second);
		} else {
			if (S.empty() || S.top() != v.second) {
				printf("NO\n");
				return 0;
			}
			S.pop();
		}
	}
	assert(S.empty());
	printf("YES\n");
}


Measured memory_bytes: 3444
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
#def f(N, k):
#    return  -(k*(k+1)*(2*k+1))//6 + (N+1) * (k*(k+1))//2 + k
def main():
    N, K = map(int, input().split())
    counter = 0
    for k in range(K, N+2):
    #    print(k * (N - k +1) + 1)
        counter += (k * (N - k +1) + 1)
    #counter = f(N, N+1) - f(N, K-1)
    print(counter%(1000000007))

if __name__ == "__main__":
    main()




Measured memory_bytes: 9096
#include<stdio.h>
int main(){
	int i=1,x;
	int dizi[10000]; 
	dizi[0]=1;
	do{
		scanf("%d",&dizi[i]);
		i++;}
	while(dizi[i-1]!=0);
	if(i!=1){
	x=i-2;
	for(i=1;i<=x;i++){
		printf("Case %d: %d\n",i,dizi[i]);}}

	return 0;
}

Measured memory_bytes: 640
S = input()
K = int(input())
lista = list(S)

flag = 0

if(K<= len(lista)):
  for i in range(K):
    if(lista[i] != "1"):
      flag = 1
      ans = lista[i]
      break
  if(flag == 0):
    print(1)
  else:
    print(ans)

else:
  i = 0
  while True:
    if(lista[i] != "1"):
      print(lista[i])
      break
    i+= 1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,x;
  cin >> n >> x;
  vint A(n);
  rep(i,0,n) cin >> A[i];
  int ans = 0;
  rep(i,1,n){
    if(A[i-1] + A[i] > x){
      ans += A[i] + A[i-1] - x;
      if(A[i-1] > x){
        A[i] = 0;
      }
      else{
        A[i] = x - A[i-1];
      }
    }
  }
  // rep(i,0,n) cout << A[i] << endl;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}

const int mo=1000000007,maxn=2000004;
int jc[2000005],ny[2000005],ans;
struct rec{int x[2],y[2];} r[3];

LL qp(LL x,LL y) {
    LL res=1;
    for(;y;y>>=1,x=x*x%mo)
	if(y&1) res=res*x%mo;
    return res;
}
LL C(int n,int m) {return n>=m&&m>=0 ? 1ll*jc[n]*ny[m]%mo*ny[n-m]%mo : 0;}  //*****
LL ways(int n,int m) {return n>=0&&m>=0 ? C(n+m+2,m+1) : 0;}     //*****
LL calc0(int x,int y) {
    LL res=ways(x-r[0].x[1]-1,y-r[0].y[1]-1)-ways(x-r[0].x[0],y-r[0].y[1]-1)-ways(x-r[0].x[1]-1,y-r[0].y[0])+ways(x-r[0].x[0],y-r[0].y[0]);
    return (res%mo+mo)%mo;
}
LL calc2(int x,int y) {
    LL res=ways(r[2].x[0]-1-x,r[2].y[0]-1-y)-ways(r[2].x[0]-1-x,r[2].y[1]-y)-ways(r[2].x[1]-x,r[2].y[0]-1-y)+ways(r[2].x[1]-x,r[2].y[1]-y);
    return (res%mo+mo)%mo;
}
int main()
{   
    for(int i=0;i<=2;++i) r[i].x[0]=gi(),r[i].x[1]=gi();
    for(int i=0;i<=2;++i) r[i].y[0]=gi(),r[i].y[1]=gi();
    for(int i=0;i<=maxn;++i) jc[i]=i?1ll*jc[i-1]*i%mo:1;
    for(int i=maxn;i>=0;--i) ny[i]=i==maxn?qp(jc[i],mo-2):1ll*ny[i+1]*(i+1)%mo;
    
    for(int i=r[1].x[0];i<=r[1].x[1];++i) {
	ans += calc0(i,r[1].y[1])*calc2(i,r[1].y[1]+1)%mo*(i+r[1].y[1])%mo , ans>=mo?ans-=mo:0;
	ans -= calc0(i,r[1].y[0]-1)*calc2(i,r[1].y[0])%mo*(i+r[1].y[0]-1)%mo , ans<0?ans+=mo:0;
    }
    for(int i=r[1].y[0];i<=r[1].y[1];++i) {
	ans += calc0(r[1].x[1],i)*calc2(r[1].x[1]+1,i)%mo*(i+r[1].x[1])%mo , ans>=mo?ans-=mo:0;
	ans -= calc0(r[1].x[0]-1,i)*calc2(r[1].x[0],i)%mo*(i+r[1].x[0]-1)%mo , ans<0?ans+=mo:0;
    }
    
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 15872
import sys
input = sys.stdin.readline


def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    A = [0] + A + [0] ## append start and goal (1-indexed table)
    diff = [0] * n # 0-indexed table
    prev = 0
    _sum = 0
    for i in range(1,n+1):
        _sum += abs(prev - A[i])
        prev = A[i]
        diff[i-1] = abs(A[i-1] - A[i+1]) - (abs(A[i]-A[i-1]) + abs(A[i+1] - A[i]))
    ## add the cost until goal.
    _sum += abs(A[n])
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 101224
n,a,b = map(int,input().split())
S = [i for i in input()]
all = 0
fore = 0
for s in range(len(S)):
    if S[s]=="a":
        if all<a+b:
            print("Yes")
            all+=1
        else:
            print("No")
    elif S[s]=="b":
        if all<a+b and fore<b:
            print("Yes")
            all+=1
            fore+=1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

vector<int> vi[50];
int main(){
    int n,m,sr,ds;
    cin>>n>>m;
    rep(i,m){
        cin>>sr>>ds;
        vi[sr-1].pb(ds-1);
        vi[ds-1].pb(sr-1);
    }
    rep(i,n){
        cout<<vi[i].size()<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int n=read();
	REP(i,1,n){
		int x=read();
		if(x&1) return printf("first\n"),0;
	}
	printf("second");
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = [int(x) for x in input().split()]

pp = [[p[i-1], p[i], p[i+1]] for i in range(1, n-1)]
print(len([x for x in pp if (x[1]>=x[0] and x[1]<=x[2]) or (x[1]<=x[0] and x[1]>=x[2])]))

Measured memory_bytes: 3188
def resolve():
    s = input()
    lis = []
    ans = ""
    for i in range(len(s)):
        if s[i] != "B":
            lis.append(s[i])
        elif s[i] == "B" and len(lis) != 0:
            lis = lis[:-1]
    for j in range(len(lis)):
        ans += lis[j]
    print(ans)
resolve()

Measured memory_bytes: 8916
import java.util.*;
import java.util.stream.*;
import java.util.function.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        
        
        System.out.println((H - h) * (W - w));
    }
}


Measured memory_bytes: 24020
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,k,b[200000]={},t,m=1;
  double a,x=0,q;
  cin >> n >> k;
  q=n;
  t=k-1;
  while(k>1){
    while(t>=(k+1)/2){
      b[t]=m;
      t--;
    }
    m++;
    k=(k+1)/2;
  }
  FOR(i,1,n+1){
    a=POW(2,b[i]);
    a=1/a;
    x+=a;
  }
  printf("% .16f",x/q);
}


Measured memory_bytes: 1792
n=int(input())
num=list(map(int,input().split()))
a=0
for i in range(1,n-1):
    if num[i-1]<num[i] and num[i]<num[i+1] or num[i-1]>num[i] and num[i]>num[i+1]:
        a += 1
print(a)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll x, y;
	ll ans = 0;

	cin >> x >> y;

	ll n = x;
	while (n <= y) {
		n *= 2;
		ans++;
	}

	cout << ans << "\n";
}

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

	solve_abc_c();

	return 0;
}

Measured memory_bytes: 256