akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define in(type,a) type a;cin >> a
using ll = long long;

int main() {
    in(ll, n);
    in(ll, a);
    in(ll, b);
    ll ans = (n/(a+b))*a;
    ans += min((n%(a+b)),a);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int W,H,x,y,r; 
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
    if(x - r < 0 || x + r > W || y - r < 0 || y + r > H){
        cout << "No" << endl;
    }else if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H ){
        cout << "Yes" << endl;
    }    
    return 0;
}


Measured memory_bytes: 3092
A, B, C = map(int, input().split())
C_list = []
if A >= B:
    num = A % B
    while num not in C_list:
        C_list.append(num)
        num += A % B
        if num >= B:
            num -= B
elif A < B:
    num = A
    while num not in C_list:
        C_list.append(num)
        num += A
        if num >= B:
            num -= B
print('YES' if C in C_list else 'NO')

Measured memory_bytes: 3060
class Rmq:
    # 平方分割
    # 値を変更すると元のリストの値も書き換わる
    def __init__(self, a, sqrt_n=500):
        from itertools import zip_longest
        self.n = len(a)
        self.sqrt_n = sqrt_n
        self.layer1 = a
        self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=float("inf"))]

    def get_min(self, l, r):
        sqrt_n = self.sqrt_n
        parent_l, parent_r = l//sqrt_n+1, (r+1)//sqrt_n
        if parent_l < parent_r:
            return min(min(self.layer0[parent_l:parent_r]),
                       min(self.layer1[l:parent_l*sqrt_n]),
                       min(self.layer1[parent_r*sqrt_n:r]))
        else:
            return min(self.layer1[l:r])

    def set_value(self, idx, val):
        self.layer1[idx] = val
        idx //= self.sqrt_n
        self.layer0[idx] = min(self.layer0[idx], val)

    def chmin(self, idx, val):
        if self.layer1[idx] > val:
            self.set_value(idx, val)

    def debug(self):
        print("layer0=", self.layer0)
        print("layer1=", self.layer1)

    def __getitem__(self, item):
        return self.layer1[item]

    def __setitem__(self, key, value):
        self.set_value(key, value)


from operator import itemgetter
import sys

def main():
    N, M = map(int, input().split())
    LRC = list(zip(*[iter(map(int, sys.stdin.read().split()))]*3))
    LRC.sort(key=itemgetter(0))
    idx_LRC = 0
    inf = 1 << 60

    rmq = Rmq([inf] * (N+1))
    rmq.set_value(1, 0)
    for v in range(1, N+1):
        d = rmq.get_min(v, N+1)
        while idx_LRC < M:
            l, r, c = LRC[idx_LRC]
            if l <= v:
                rmq.chmin(r, d+c)
                idx_LRC += 1
            else:
                break
    ans = rmq[N]
    print(ans if ans < inf else -1)

main()


Measured memory_bytes: 40936
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define pb push_back
#define pc __builtin_popcount
#define pcll __builtin_popcountll
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
using namespace std;
int n, a, b, c;
ss s[500005];
char ans[500005];
void rec(int v, int a, int b, int c) {
  if (v > n) {
    cout << "Yes\n";
    for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
    exit(0);
  }
  if (s[v] == "AB") {
    if (a) ans[v] = 'B', rec(v + 1, a - 1, b + 1, c);
    if (b) ans[v] = 'A', rec(v + 1, a + 1, b - 1, c);
  } else if (s[v] == "AC") {
    if (a) ans[v] = 'C', rec(v + 1, a - 1, b, c + 1);
    if (c) ans[v] = 'A', rec(v + 1, a + 1, b, c - 1);
  } else {
    if (b) ans[v] = 'C', rec(v + 1, a, b - 1, c + 1);
    if (c) ans[v] = 'B', rec(v + 1, a, b + 1, c - 1);
  }
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n >> a >> b >> c;
  forn(n) cin >> s[i];
  rec(1, a, b, c);
  cout << "No\n";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 27192
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    int N;
    cin >> N;
    int nums_position[N];
    for(int i = 0; i < N; i++){
        int num;
        cin >> num;
        nums_position[num - 1] = i;
    }
    int ans = 0, continuity = 1;
    for(int i = 1; i < N; i++){
        if(nums_position[i - 1] < nums_position[i]){
            continuity++;
        }else{
            ans = max(ans, continuity);
            continuity = 1;
        }
    }
    ans = max(ans, continuity);
    cout << N - ans << endl;
}




Measured memory_bytes: 1024
def solver():
	N = int(input())
	action = []
	for i in range(N):
		action.append(list(map(int, input().split())))

	dp = [[0 for _ in range(3)] for _ in range(N)]

	for i in range(3):
		dp[0][i] = action[0][i]

	for i in range(1,N):
		dp[i][0] = max(dp[i-1][1] + action[i][0], dp[i-1][2] + action[i][0])
		dp[i][1] = max(dp[i-1][0] + action[i][1], dp[i-1][2] + action[i][1])
		dp[i][2] = max(dp[i-1][0] + action[i][2], dp[i-1][1] + action[i][2])
	print(max(dp[N-1]))

solver()

Measured memory_bytes: 47368
d,n=map(int,input().split())

import math

max_it=int(math.log(n, 2))+1
mn_d=min(d,n)
p=0

for i in range(1,mn_d+1):
	for j in range(1,max_it+1):
		if i*2**j>=n:
			if i<n:
				p+=1/d*0.5**j
			break

if d>=n:
	p+=(d-n+1)/d

print(p)

Measured memory_bytes: 3060
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <stack>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

int main(){
	int n,k;
	cin>>n>>k;
	LL a[1111]={};
	FOR(i,1,n+1){
		cin>>a[i];
		a[i]+=a[i-1]*1LL;
	}
	vector<LL> val;
	FOR(i,1,n+1){
		FOR(j,i,n+1){
			val.PB(a[j]-a[i-1]);
		}
	}
	//FOR(i,0,val.size())cerr<<val[i]<<" ";
	//cerr<<endl;
	LL ans=0;
	FORD(i,41,0){
		LL tmp=1LL<<i;
		vector<LL> val2;
		int cnt=0;
		int l=val.size();
		FOR(j,0,l){
			if(val[j]&tmp){
				val2.PB(val[j]);
				cnt++;
			}
		}
		if(cnt>=k){
			val=val2;
			ans+=tmp;
		}
	}
	cout<<ans<<endl;
	 return 0;
}


Measured memory_bytes: 6256
#include<iostream>
#include<cmath>
 
using namespace std;
 
int main(){
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++)
    cin>>h[i];
 
  int dp[n];
  dp[0]=0;
  for(int i=1;i<n;i++){
    dp[i]=INT_MAX;
    
    for(int j=max(0,i-k);j<i;j++){
      int cost=dp[j]+abs(h[i]-h[j]);
      dp[i]=min(dp[i],cost);
    }
  }
 
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 3924
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n,m,t; cin >> n >> m >> t;
	vb v(t,false);
	rep(i,n){
		ll x; cin >> x;
		REP(j,x-m,min(t,x+m)) v[j] = true;
	}
	ll ans = 0;
	rep(i,t) if(!v[i]) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using static Assistant.Input;
using System.Linq;
using Assistant;

namespace AOJ_ALDS1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = ReadInt;
            var a = ReadInts;

            KeyValue[] keyValues = new KeyValue[n];
            for (int i = 0; i < n; i++)
            {
                keyValues[i] = new KeyValue() { index = i, value = a[i] };
            }
            keyValues = keyValues.OrderBy(x => x.value).ToArray();

            for (int i = 0; i < n; i++)
            {
                a[keyValues[i].index] = i + 1;
            }

            long swapCount = 0;
            BIT bit = new BIT(n);

            for (int i = 0; i < n; i++)
            {
                swapCount += bit.Sum(0, n) - bit.Sum(0, a[i]);
                bit.Add(a[i], a[i], 1);
            }

            Console.WriteLine(swapCount);
        }

        struct KeyValue
        {
            public int index { get; set; }
            public int value { get; set; }
        }


    }

    class BIT
    {
        long[] bit0, bit1;  //1-indexed
        int n;
        public BIT(int n)
        {
            bit0 = new long[n + 1];
            bit1 = new long[n + 1];
            this.n = n;
        }

        public long Sum(int l, int r)
        {
            long ret = 0;
            ret += Sum(bit0, r) + Sum(bit1, r) * r;
            ret -= Sum(bit0, l - 1) + Sum(bit1, l - 1) * (l - 1);
            return ret;
        }

        long Sum(long[] bit, int i)
        {
            long s = 0;
            while (i > 0)
            {
                s += bit[i];
                i -= i & -i;
            }
            return s;
        }

        public void Add(int l, int r, int a)
        {
            Add(bit0, l, -a * (l - 1));
            Add(bit1, l, a);
            Add(bit0, r + 1, a * r);
            Add(bit1, r + 1, -a);
        }

        void Add(long[] bit, int i, int a)
        {
            while (i <= n)
            {
                bit[i] += a;
                i += i & -i;
            }
        }
    }

}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        //drawmap
        //drawarray
    }


}



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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
#define Puts(b) cout<<(b? "Yes":"No")<<endl
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  cin >> n;
  vi v(n);
  rep(i, 0, n) cin >> v[i];

  map<int, int> mp1, mp2;
  for(int i = 0; i < n; i += 2) mp1[v[i]]++;
  for(int i = 1; i < n; i += 2) mp2[v[i]]++;

  int ans = INF;
  {
    int cou1 = INF;
    int num = -1;
    for(auto it : mp1) {
      if(cou1 > n / 2 - it.second) {
        cou1 = n / 2 - it.second;
        num = it.first;
      }
    }
    int cou2 = INF;
    for(auto it : mp2) {
      if(cou2 > n / 2 - it.second && num != it.first) cou2 = n / 2 - it.second;
    }
    if(cou2 == INF) cou2 = n / 2;
    ans = min(ans, cou1 + cou2);
  }
  {
    int cou1 = INF;
    int num = -1;
    for(auto it : mp2) {
      if(cou1 > n / 2 - it.second) {
        cou1 = n / 2 - it.second;
        num = it.first;
      }
    }
    int cou2 = INF;
    for(auto it : mp1) {
      if(cou2 > n / 2 - it.second && num != it.first) cou2 = n / 2 - it.second;
    }
    if(cou2 == INF) cou2 = n / 2;
    ans = min(ans, cou1 + cou2);
  }
  cout << ans << endl;
}


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

int main(){
    int n;
    cin>>n;
    int ans = 0;
    vector<int> v(n);
    vector<int> c(n);
    for(int i=0;i<n;++i){
      cin>>v[i];
    }
    for(int i=0;i<n;++i){
      cin>>c[i];
    }
    for(int i=0;i<n;++i){
        if(v[i]-c[i]>0) ans+=(v[i]-c[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[302] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, j, N, M, A[301][301];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= M; j++) scanf("%d", &(A[i][j]));
	}
	
	int k, m, min = 1000, flag[301] = {}, p[302];
	data d[302];
	for (i = 1; i <= M; i++) flag[i] = 1;
	for (m = M; m >= 1; ) {
		for (i = 1, k = 0; i <= M; i++) {
			if (flag[i] == 1) {
				d[k].key = 0;
				d[k].id = i;
				p[i] = k++;
			}
		}
		
		for (i = 1; i <= N; i++) {
			for (j = 1; j <= M; j++) {
				if (flag[A[i][j]] == 1) {
					d[p[A[i][j]]].key++;
					break;
				}
			}
		}
		merge_sort(d, k);
		if (d[k-1].key < min) min = d[k-1].key;
		for (flag[d[--k].id] = 0, m--; k > 0 && d[k].key == d[k-1].key; flag[d[--k].id] = 0, m--);
	}
	
	printf("%d\n", min);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2092
def dpdo(left, right):
    if dp[left][right]!=-1:
        return dp[left][right]
    elif left==right:
        dp[left][right] = grid[left][right]
        return dp[left][right]
    elif right-left==1:
        dp[left][right] = dpdo(left,right-1) + dpdo(left+1, right) + grid[left][right]
        return dp[left][right]
    else:
        dp[left][right] = dpdo(left,right-1) + dpdo(left+1, right) + grid[left][right] - dpdo(left+1,right-1)
        return dp[left][right]

dp = []
grid = []
temp1 = []
temp2 = []
for i in range(0,501):
    temp1 = []
    temp2 = []
    for j in range(0,501):
        temp1.append(0)
        temp2.append(-1)
    dp.append(temp2)
    grid.append(temp1)
    
n, m, q = map(int,input().split())
for i in range(1,m+1):
    left, right = map(int, input().split())
    grid[left][right] += 1
    
dpdo(1,n)

for i in range(1,q+1):
    left, right = map(int, input().split())
    print(dp[left][right])

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<char>>v(m,vector<char>(2));
    for(int i=0; i<m; i++){
        cin>>v.at(i).at(0)>>v.at(i).at(1);
    }
    string c;
    for(int i=0; i<n; i++){
        c+='o';
    }

    for(int i=0; i<m; i++){
        if(c.at(v.at(i).at(0)-'0'-1)!='o') {
            if(c.at(v.at(i).at(0)-'0'-1)!=v.at(i).at(1)){
                cout<<"-1"<<endl;
                return 0;
            }
        }
        else c.at(v.at(i).at(0)-'0'-1)=v.at(i).at(1);
    }
    if(n!=1 and c.at(0)=='o') c.at(0)='1';
    for(int i=0; i<n; i++){
        if(c.at(i)=='o') c.at(i)='0';

    }
    string ans;
    if(n==1 and c.at(0)=='0'){
        cout<<'0'<<endl;
        return 0;
    }
    if(c.at(0)=='0'){
        cout<<"-1"<<endl;
        return 0;
    }
    if(c.at(0)!='0'){
        for(int i=0; i<n; i++){
            ans+=c.at(i);
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long min = Long.MAX_VALUE;
		for (int i = 0; i < 5; i++) {
			min = Math.min(min, sc.nextLong());
		}
		sc.close();

		System.out.println((n + min - 1) / min + 4);
	}
}


Measured memory_bytes: 23380
#include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
constexpr long long int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

void Calculate_Depth(vector<vector<pair<int,long long int>>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i.first] > depth[cn] + 1) {
				depth[i.first] = depth[cn] + 1;
				Q.push(i.first);
			}
		}
	}
	return;
}

void Search(vector<vector<pair<int,long long int>>>&edge,vector<int>&depth,vector<int>&parent,vector<int>&path_cost,vector<int>&path,vector<long long int>&weight,vector<int>&used,int node,string &ans){
	used[node]++;
	vector<pair<long long int,int>>cost;
	for(auto i:edge[node]){
		if(depth[i.first]<depth[node])continue;
		cost.push_back({weight[i.first],i.first});
	}
	sort(cost.begin(),cost.end());
	for(auto i:cost){
		if(K*used[node]>=i.first%MOD){
			ans="No";
			return;
		}
		Search(edge,depth,parent,path_cost,path,weight,used,i.second,ans);
	}
	if(parent[node]==-1)return ;
	if(path[node])return;
	if(K*(used[node]+used[parent[node]])>=path_cost[node])ans="No";
	return;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N>>K>>L>>R;
	L--;
	R--;
	vector<vector<pair<int,long long int>>>edge(N);
	for(int i=1;i<N;i++){
		int a,b,c;
		cin>>a>>b>>c;
		a--;
		b--;
		edge[a].push_back({b,c});
		edge[b].push_back({a,c});
	}
	vector<int>depth(N,MOD);
	Calculate_Depth(edge,depth,L);
	vector<int>parent(N,-1);
	vector<int>path_cost(N);
	for(int i=0;i<N;i++){
		for(auto j:edge[i]){
			if(depth[j.first]<depth[i]){
				parent[i]=j.first;
				path_cost[i]=j.second;
			}
		}
	}
	vector<int>path(N);
	int cn=R;
	while(cn!=L){
		path[cn]=1;
		cn=parent[cn];
	}
	path[L]=1;
	vector<long long int>weight(N);
	for(int i=0;i<N;i++){
		if(i==L)continue;
		weight[i]=path_cost[i];
		if(path[i])weight[i]+=MOD;
	}
	vector<int>used(N);
	used[L]=-1;
	string ans="Yes";
	Search(edge,depth,parent,path_cost,path,weight,used,L,ans);
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 14332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemC solver = new ProblemC();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			final int MOD = (int) (1e9 + 7);
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
			}
			int[] b = new int[n];
			for (int i = 0; i < n; i++) {
				b[i] = in.nextInt();
			}
			int[] l1 = new int[n];
			int[] r1 = new int[n];
			for (int i = 0; i < n; i++) {
				r1[i] = a[i];
				if (i == 0 || a[i] != a[i - 1]) {
					l1[i] = a[i];
				} else {
					l1[i] = 1;
				}
			}
			int[] l2 = new int[n];
			int[] r2 = new int[n];
			for (int i = n - 1; i >= 0; i--) {
				r2[i] = b[i];
				if (i == n - 1 || b[i] != b[i + 1]) {
					l2[i] = b[i];
				} else {
					l2[i] = 1;
				}
			}
			long ans = 1;
			for (int i = 0; i < n; i++) {
				int l = Math.max(l1[i], l2[i]);
				int r = Math.min(r1[i], r2[i]);
				if (l <= r) {
					ans = ans * (r - l + 1) % MOD;
				} else {
					ans = 0;
				}
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

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

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

	}
}



Measured memory_bytes: 33112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int H = sc.nextInt(), W = sc.nextInt();
            if(H==0 && W==0) {
                break;
            }
            for(int i=0; i<H; i++) {
                for(int j=0; j<W; j++) {
                    System.out.printf((i%2==0 && j%2==0) || (i%2!=0 && j%2!=0) ? "#" : ".");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


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

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

  int ans = 0;
  int last = 0;

  for (int i = 0; i < N; i++) {
    int now; cin >> now;
    if (now - last > 0) ans += now - last;
    last = now;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<i32>();

    let num = partition(&mut a, 0, n);
    print_vec_part(&a, num as usize);
}

fn partition(a: &mut [i32], p: i32, r: usize) -> i32 {
    let x = a[r - 1];

    let mut i = p - 1;
    for j in p as usize..r {
        if a[j] <= x {
            i += 1;
            a.swap(i as usize, j);
        }
    }
    i
}


fn print_vec_part<T: std::fmt::Display>(v: &Vec<T>, num: usize) {
    for a in &v[0..num] {
        print!("{} ", a);
    }
    print!("[{}] ", v[num]);
    for a in &v[num + 1..v.len() - 1] {
        print!("{} ", a);
    }
    println!("{}", v[v.len() - 1]);
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5040
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>
#include <iomanip>
#include <iterator>

// #define MOD 1000000007
// #define INF 1000000001

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}

int main(int argc, char const *argv[]) {
    ll K;
    cin >> K;
    int N = 50;
    cout << N << endl;
    // int N; cin >> N;
    int m = K % N;
    for (int i = 0; i < N; ++i) {
        ll a;
        if (i < m) {
            a = N + K/N;
        } else {
            a = N-1-m + K/N;
        }
        cout << a << (i < N-1 ? " " : "");
    }
    cout << endl;
    return 0;
}


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

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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;

	rep(i, h) {
		rep(j, w) {
			string s;
			cin >> s;
			if (s == "snuke")
				cout << char('A' + j) << i + 1 << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
Kaijo = [1 for _ in range(N)]
for i in range(2,N+1):
  Kaijo[-i] = Kaijo[1-i]*i
#print(Kaijo)
L = [i+1 for i in range(N)]
P = list(map(int,input().split()))
PN = 0
for i in range(N-1):
  k = bisect.bisect_left(L, P[i])
  L.remove(P[i])
  PN += k*Kaijo[i+1]
#print(PN)
L = [i+1 for i in range(N)]
Q = list(map(int,input().split()))
QN = 0
for i in range(N-1):
  k = bisect.bisect_left(L, Q[i])
  L.remove(Q[i])
  QN += k*Kaijo[i+1]
ans = abs(PN-QN)
print(ans)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string a,b;
  cin>>a>>b;
  int ans=0;
  rep(i,3){
    if(a[i]==b[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int d, t, s;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> d >> t >> s;
	if (d <= s * t)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long int lli;

int main(){
    lli n;
    cin >> n;
    lli amax=1;
    if(n%2==0) amax=2;
    for(lli i=3; i*i<=n; i+=2){
        if(n%i==0) amax=i;
    }
    lli b = n/amax;
    int ans = 0;
    while(b!=0){
        b /= 10;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }
int n, m;
arr<int> G;
arr<bool> d;
vector<bool> seen;


int main()
{
    cin >> n >> m;
    
    G.resize(n);
    // d.resize(n, vector<bool>(n, 0));
    rep(i, m){
        int a, b; cin >> a >> b;
        a--; b--;
        // if(d[a][b]) continue;
        // d[a][b] = true;
        // d[b][a] = true;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.assign(n, false);
    // prarr(G);

    int s = 0;
    rep(i, n){
        if(seen[i]) continue;
        seen[i] = true;
        int t = 1;
        queue<int> que;
        que.push(i);

        while(!que.empty()){
            int a = que.front(); que.pop();
            for(auto p: G[a]){
                if(seen[p]) continue;
                seen[p] = true;
                t++;
                que.push(p);
            }
        }

        chmax(s, t);
    }
    pr(s);
    return 0;}

Measured memory_bytes: 14748
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct item_t {
	int w;
	int v;
} ;

int compare_item(const void *a, const void *b) {
  struct item_t *A = (struct item_t *)a;
  struct item_t *B = (struct item_t *)b;
  return A->w - B->w;
}

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}


int main(void)
{
	//変数の宣言
	int n;
	long int weight;
	int i,j,k,l;
	struct item_t item[110];
	long int kati[4][110];
	long int katilen[4]={0,0,0,0};
	long int katisum[4][110];
	long int temp;
	long int w1;
	long int ans;
	
	//データの読み込み
	scanf("%d %ld",&n,&weight);
	
	for(i=0;i<n;i++){
		scanf("%d %d",&item[i].w,&item[i].v);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	w1=item[0].w;
	qsort(item, n, sizeof(struct item_t), compare_item);
	
//	printf("qsort１回目完了\n");
	for(i=0;i<n;i++){
//		printf("w=%d,v=%d\n",item[i].w,item[i].v);
	}
	
	j=0;
	k=0;
	for(i=0;i<n;i++){
		if(i==0){
			//なにもしない
		}else if(item[i].w!=item[i-1].w){
			katilen[j]=k+1;
			j++;
			k=0;
		}else{
			k++;
		}
		kati[j][k]=item[i].v;
	}
	katilen[j]=k+1;
	
	
	for(i=0;i<4;i++){
		qsort(kati[i], katilen[i], sizeof(long int), compare_int);
		for(j=0;j<katilen[i];j++){
			if(j==0){
				katisum[i][j]=kati[i][j];
			}else{
				katisum[i][j]=katisum[i][j-1]+kati[i][j];
			}
		}
	}
	
	for(i=0;i<4;i++){
//		printf("w=%dの価値配列は\n{",w1+i);
		for(j=0;j<katilen[i];j++){
			if(j==0){
//				printf("%d",katisum[i][j]);
			}else{
//				printf(",%d",katisum[i][j]);
			}
		}
//		printf("}\n");
	}
	
	ans=0;
	for(i=0;i<katilen[0]+1;i++){
		for(j=0;j<katilen[1]+1;j++){
			for(k=0;k<katilen[2]+1;k++){
//				printf("i=%d,j=%d,k=%d,wsum=%d\n",i,j,k,w1*i+(w1+1)*j+(w1+2)*k);
				
				if(weight-w1*i-(w1+1)*j-(w1+2)*k>=0){
					l=(weight-w1*i-(w1+1)*j-(w1+2)*k)/(w1+3);
					if(l>katilen[3]) l=katilen[3];
					temp=0;
					if(i!=0) temp=temp+katisum[0][i-1];
					if(j!=0) temp=temp+katisum[1][j-1];
					if(k!=0) temp=temp+katisum[2][k-1];
					if(l!=0) temp=temp+katisum[3][l-1];
					
//					printf("i=%d,j=%d,k=%d,l=%d,temp=%d\n\n",i,j,k,l,temp);
					if(ans<temp) ans=temp;
				}
			}
		}
	}
	
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	
	printf("%ld",ans);
	
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC150B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < N - 2; i++)
            {
                if (S[i].ToString() == "A")
                {
                    if (S[i + 1].ToString() == "B")
                    {
                        if (S[i + 2].ToString() == "C")
                        {
                            count += 1;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

int main(){
    i64 a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||a+c==b||b+c==a){
    cout<<"Yes"<<endl;
    return 0;
    } 
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 1e7 + 2;
int c[nax];
long long ans;
int n;

int main () {
    scanf("%d", &n);

    for (int i = 1 ; i < nax; ++ i) {
        for (int j = i ; j < nax; j += i)
            ++ c[j];
    }

    for (int k = 1 ; k <= n ; ++ k) {
        ans += 1LL * c[k] * k;
    }

    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


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


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int main() {
    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++)cin>>a[i];
    int m = *min_element(a.begin(), a.end());
    int M = *max_element(a.begin(), a.end());
    long long ans=INFLL;
    for(int i=m;i<=M;i++){
        long long count =0;
        for(int j=0;j<N;j++){
            count+=pow(a[j]-i, 2);
        }
        if(ans>count) ans=count;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<k;i++){
        cout<<s<<" ";
    }
    for(int i=0;i<n-k;i++){
        cout<<1000000000-(s==1000000000)<<" ";
    }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;
const int MAX = 510000;
const int MOD = 1000000007;
 
 
 
int main(){
ll a,b,c;
  cin>>a>>b>>c;
  a=a-c;
  if(a<0) b=b+a;
  if(a<0) a=0;
  if(b<0) b=0;
  cout<<a<<' '<<b;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin >> n >> m;
  int L=0;
  int R=n;
  for(int i=0;i<m;i++){
    int l,r;
    cin >> l >> r;
    if(L<l) L=l;
    if(r<R) R=r;
  }
  if(R-L+1>=0){
    cout << R-L+1 << endl;
  }
  else cout << 0 << endl;
}


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

int main() {
	std::string a, b;
	std::cin >> a>>b;
	if (a == b) {
		std::cout << "EQUAL";
	} else if (a.length() > b.length()) {
		std::cout << "GREATER";
	} else if (a.length() < b.length()) {
		std::cout <<"LESS";
	} else {
		for (int i = 0; i < a.length(); i++) {
			if (a[i] > b[i]) {
				std::cout << "GREATER";
				break;
			} else if (a[i] < b[i]) {
				std::cout <<"LESS";
				break;
			}
		}
	}
	std::cout <<std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;

int main(){
    ll i,j;
    ll n;
    cin>>n;
    string s;
    ll c[26];
    cin>>s;

    for(i=0;i<26;i++) c[i]=1;

    for(i=0;i<n;i++){
        c[s[i]-'a']++;
    }
    ll ans=1;

    for(i=0;i<26;i++){
        ans*=c[i];
        ans%=Mod;
    }

    cout<<(ans+Mod-1)%Mod<<endl;

    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
    #define N 255555
    #define F(i,l,r) for(int i=l;i<=r;++i)
    #define D(i,r,l) for(int i=r;i>=l;--i)
    #define Fs(i,l,r,c) for(int i=l;i<=r;c)
    #define Ds(i,r,l,c) for(int i=r;i>=l;c)
    #define Tra(i,u) for(int i=G.Start(u),__v=G.To(i);~i;i=G.Next(i),__v=G.To(i))
    #define MEM(x,a) memset(x,a,sizeof(x))
    #define FK(x) MEM(x,0)

    int n,a[N],b[N];
    void R1(int &x)
    {
        x=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x=(f==1)?x:-x;
    }
    void Input()
    {
        R1(n);
        F(i,1,n) R1(a[i]);
        F(i,1,n) R1(b[i]);
    }
    int c[N],d[N];
    void Soviet()
    {
        int ans=0;
        F(i,0,28)
        {
            int m=(1<<i);
            F(j,1,n) c[j]=a[j]%(m<<1),d[j]=b[j]%(m<<1);
            
            sort(c+1,c+n+1);
            sort(d+1,d+n+1);
            int l,r,sum=0;
            F(j,1,n)
            {
                l=lower_bound(d+1,d+n+1,1*m-c[j])-d;
                r=lower_bound(d+1,d+n+1,2*m-c[j])-d-1;
                sum+=(r-l+1);
                l=lower_bound(d+1,d+n+1,3*m-c[j])-d;
                r=lower_bound(d+1,d+n+1,4*m-c[j])-d-1;
                sum+=(r-l+1);
            }
            if (sum&1) ans+=m;
        }
        printf("%d\n",ans);
    }

    #define Flan void
    Flan IsMyWife()
    {
        Input();
        Soviet();
    }
}
int main()
{
    Flandre_Scarlet::IsMyWife();
    getchar();getchar();
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main(void)
{
    double r;
    double s, c;
    double p;

    scanf("%lf", &r);

    p = 3.141592653589;

    s = r * r * p;
    c = (r + r) * p;
   
    printf("%f %f\n", s, c);

    return 0;
}



Measured memory_bytes: 2764
N, M = map(int, input().split())
# N頂点M辺のグラフ
# 自己ループ (a1==b1)は存在しない
# 二重辺(a1,b1 と a2,b2が同じもの)は存在しない
# 一辺取り除いた時に分離してしまう辺を橋と呼ぶ


# union find
# 最初は全て値であるとして初期化する parents[i] = i

# root(x) => xの根を返す関数
# unit(x,y) => root(x)とroot(y)が同じであればそのまま。違う場合は、xの根であるroot(x)をyの根であるroot(y)につける. 根が同じでない二つの木を合併する。
# same(x,y) => 二つのデータx,yが属する木が同じ場合、trueを返す。if root(x) == root(y)するだけ
parents = None


def root(x):
    if parents[x] == x:
        return x
    parents[x] = root(parents[x])
    return parents[x]


count = 0


def unit(x, y):
    root_x = root(x)
    root_y = root(y)
    if root_x < root_y:
        parents[root_y] = root_x
    else:
        parents[root_x] = root_y


def same(x, y):
    root_x = root(x)
    root_y = root(y)
    return (root_x == root_y)


es = []
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    es.append((a, b))

ans = 0
for i in range(M):
    parents = [k for k in range(N)]
    for j, e in enumerate(es):
        if j == i:
            continue
        a, b = e
        unit(a, b)
    a, b = es[i]
    if not same(a, b):
        ans += 1
print(ans)


Measured memory_bytes: 40560
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int H,W;
  cin>>H>>W;
  
  vector<vector<char>> vec(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>vec[i][j];
    }
  }
  
  vector<vector<char>> ans(H+2,vector<char>(W+2));
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      if(i==0){
        ans[i][j]='#';
      }
      else if(i==H+1){
        ans[i][j]='#';
      }
      else{
        if(j==0||j==W+1){
          ans[i][j]='#';
        }
        else{
          ans[i][j]=vec[i-1][j-1];
        }
      }
    }
  }
  
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout<<ans[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 998244353 
#define int long long
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000005
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define PI M_PI
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}


void solve()
{   
   int n,n1;cin >> n;
   string ans="";
   while(n>0)
   {
     n1=n%26;
     if(n1==0)
     {
       ans+='z';
       n=n/26;
       n--;
     }
     else
    {ans+=('a'+(n1-1));
     n=n/26;
    }
   }
   reverse(all(ans));
   cout << ans;
}

signed main()
{ boost
  int test=0,t;
    //cin >> t ;
    t=1;
   while(test++ <t){
	  //cout<<"Case #"<<test<<": ";
	   solve();}
  
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

void dfs(int u,int v,vector<vector<char>>& M,vector<vector<int>>& F){
	F[v][u]=1;
	switch(M[v][u]){
	case '>':
		if(F[v][u+1]){
			out("LOOP");
			return ;
		}
		dfs(u+1,v,M,F);
		break;
	case '<':
		if(F[v][u-1]){
			out("LOOP");
			return ;
		}
		dfs(u-1,v,M,F);
		break;
	case 'v':
		if(F[v+1][u]){
			out("LOOP");
			return ;
		}
		dfs(u,v+1,M,F);
		break;
	case '^':
		if(F[v-1][u]){
			out("LOOP");
			return ;
		}
		dfs(u,v-1,M,F);
		break;
	default:
		out(u,v);
		return;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	while(true){
		int H=in(),W=in();
		if(!H && !W) break;
		vector<vector<char>> M(H,vector<char>(W));
		vector<vector<int>> F(H,vector<int>(W,0));
		REP(i,H){
			string S=in<string>();
			REP(j,W){
				M[i][j]=S[j];
			}
		}

		dfs(0,0,M,F);
	}
	return 0;
}



Measured memory_bytes: 3152
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
X, Y, A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
ps = list(map(int, stdin.readline().rstrip().split()))
qs = list(map(int, stdin.readline().rstrip().split()))
rs = list(map(int, stdin.readline().rstrip().split()))

ps.sort()
qs.sort()

del ps[0:A-X]
del qs[0:B-Y]

l = ps + qs + rs

l.sort()
del l[0:len(l)-X-Y]

print(sum(l))


Measured memory_bytes: 23328
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
#include <limits.h>
using namespace std;
typedef long long LL;
const int N=40;
typedef pair<string,int> psi;

int n;
char s[N],s1[N],s2[N];
map<psi,int> mp1,mp2;

void process(char *str,map<psi,int> &mp) {
	for(int s=0;s<(1<<n);s++) {
		string x="";
		int c=0;
		for(int i=0;i<n;i++) {
			if((s>>i)&1) {
				c++;
				x.push_back(str[i]);
			}
		}
		for(int i=n-1;i>=0;i--) {
			if((s>>i)&1) continue;
			x.push_back(str[i]);
		}
		mp[psi(x,c)]++;
	}
}

int main() {
	scanf("%d %s",&n,s);
	for(int i=0;i<n;i++) {
		s1[i]=s[i];
		s2[i]=s[2*n-1-i];
	}
	s1[n]=s2[n]='\0';
	process(s1,mp1);
	process(s2,mp2);
	LL ans=0;
	map<psi,int>::iterator it;
	for(it=mp1.begin();it!=mp1.end();it++) {
		psi p=(*it).first;
		//string str=(*it).first;
		if(mp2.find(p)==mp2.end()) continue;
		int x=(*it).second;
		int y=mp2[p];
		//cout<<p.first<<" "<<p.second<<" "<<x<<" "<<y<<endl;
		ans+=(LL)x*y;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 73984
K = gets.to_i
ct = 1
x = [1]
n = 0
$ct = 0
def f(n,d,x)
  if d >= 0 && d <=9
    if n <= 0
      $ct += 1
      if $ct == K
        p x*10+d
        exit
      end
    else
      f(n-1,d-1,x*10+d) 
      f(n-1,d,x*10+d)
      f(n-1,d+1,x*10+d)
    end
  end
end
(1..100).each do |n|
  (1..9).each do |d|
    f(n-1,d,0)
  end
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int a[105],b[105];
int main()
{
	int n;
	while(cin >> n){
		for(int i = 0; i < n - 1; i++)
			cin >> b[i];
		int sum = b[0] + b[n - 2];
		for(int i = 0; i < n - 2; i++)
			sum += min(b[i],b[i + 1]);
		cout << sum << endl;
	}
	return 0;
} 

Measured memory_bytes: 256