akhauriyash/Code-Regression huggingface dataset:
import collections
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

class edge:
    def __init__(self, to, id): self.to, self.id = to, id

def main():
    N = Z()
    col = [0] * (N-1)
    G = collections.defaultdict(list)
    for i in range(N-1):
        a, b = ZZ()
        G[a].append(edge(b, i))
        G[b].append(edge(a, i))
    numCol = 0
    for i in range(1, N+1): numCol = max(numCol, len(G[i]))

    def dfs(v):
        colSet = set()
        for ed in G[v]:
            if col[ed.id] != 0: colSet.add(col[ed.id])
        c = 1
        for ed in G[v]:
            if col[ed.id] != 0: continue
            while c in colSet: c += 1
            col[ed.id] = c
            c += 1
            dfs(ed.to)

    dfs(1)
    print(numCol)
    for i in range(N-1): print(col[i])

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 113576
h, w = map(int, input().split())
cells = [[c for c in input()] for i in range(h)]


for y in range(h):
    for x in range(w):
        if cells[y][x] == '.':
            continue
        is_alone = True
        for dy,dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            ny = y+dy
            nx= x+dx
            if 0<=ny<h and 0<=nx<w and cells[ny][nx] == '#':
                is_alone = False
                break
        if is_alone:
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define MAX 1002
typedef long long ll;

int make(string a, string b){

	int dp[MAX][MAX] = {};
	
	a = ' ' + a;
	b = ' ' + b;

	int len_a = a.size();
	int len_b = b.size();

	FOR(i,1,len_a){
	FOR(j,1,len_b){
	if (a[i]==b[j]) dp[i][j] = 1 + dp[i-1][j-1];
	else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
	}
	}

	return dp[len_a-1][len_b-1];
} 	
	

int main(){
	int q;
	cin >> q;
	string str1,str2;
	rep(i,q){
	cin >> str1>>str2;
	cout << make(str1,str2) << endl;
	}
	return 0;
}



Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main() {
    int n, m;
    cin >> n >> m;
    vector<P> store(n);
    rep(i, n) {
        cin >> store[i].first >> store[i].second;
    }
    sort(store.begin(), store.end());
    int cnt = 0;
    ll sum = 0;
    for(int i=0;i<n;i++) {
        if(cnt + store[i].second >= m) {
            sum += store[i].first * (m - cnt);
            break;
        }else {
            sum += store[i].first * store[i].second;
            cnt += store[i].second;
        }
    }
    cout << sum;
}


Measured memory_bytes: 1792
import sys
from collections import deque
input = sys.stdin.readline

def max_distance(board, H, W, x, y):
    check = [[False] * W for i in range(H)]
    ans = 0
    q = deque()
    q.append((x, y, 0))
    check[y][x] = True
    while len(q) > 0:
        x, y, cost = q.popleft()
        ans = max(ans, cost)
        for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
            if 0 <= nx and nx < W and 0 <= ny and ny < H:
                if not check[ny][nx] and board[ny][nx] == ".":
                    q.append((nx, ny, cost + 1))
                    check[ny][nx] = True
    return ans

    

def main():
    H, W = map(int, input().split())
    board = [input().strip() for i in range(H)]

    ans = 0
    for y in range(H):
        for x in range(W):
            if board[y][x] == ".":
                tmp = max_distance(board, H, W, x, y)
                # print(x, y, tmp)
                ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>

int main(){
    char s[15];
    char t[15];
    //if(fgets(s, 10, stdin)==NULL){return 0;}
    //if(fgets(t, 11, stdin)==NULL){return 0;}
    if(scanf("%10s%*[^\n]%*c", s)==EOF){return 0;}
    if(scanf("%11s%*[^\n]%*c", t)==EOF){return 0;}
    int len = strlen(s);
    //printf("%s %s", s, t);
    for(int i = 0; i < len; i++){
        if(s[i]!=t[i]){
            printf("No\n");return 0;
        }
    }
    if(t[len+1]!= '\0'){printf("No\n");return 0;}

    printf("Yes\n");return 0;


}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  string s;
  cin >> N >> s;
  int ans = 1;
  for (int i = 0; i < N-1; i++){
    bool count = true;
    if (s.at(i) == s.at(i+1)) count = false;
    if (count) ans++;
  }
  cout << ans << endl;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int n;
    cin>>n;
    vector<ll> a(n);
    ll one,two,four;
    one=two=four=0;
    rep(i,0,n){
        cin>>a[i];
        if(a[i]%4==0)four++;
        else if(a[i]%2==0) two++;
        else one++;
        
    }
    if(two==0)
        cout<<(one<=four+1 ? "Yes" : "No")<<endl;
    else{
        cout<<(one<=four ? "Yes" : "No")<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
import sys
n, k, c = [int(x) for x in input().split()]
s = input()
counts = [[0] * 2 for i in range(n)]
for i in range(n):
    if s[i] == 'x':
        if i > 0:
            counts[i] = [max(counts[i - 1]), 0]
        else:
            counts[0]= [0, 0]
        continue
    if i == 0:
        counts[0]= [0, 1]
    elif i <= c:
        counts[i] = [max(counts[i - 1]), 1]
    else:
        counts[i] = [max(counts[i - 1]), max(counts[i - c - 1]) + 1]
r = []
checkk = k
nextgap = n
for i in range(n - 1, -1, -1):
    if i < nextgap and counts[i][1] >= checkk:
        if counts[i][0] < checkk:
            r.append(i + 1)
        checkk -= 1
        if checkk == 0:
            break
        nextgap = i - c
for i in range(len(r) - 1, -1, -1):
    print(r[i])


    

        


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  string s;
  cin >> s;
  vector<bool> alpha(26,true);
  REP(i,s.length()){
    alpha[s[i]-'a'] = false;
  }
  if(s.length()==26){
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
      cout << -1 << endl;
      return 0;
    }
    ll ma = s[s.length()-1]-'a';
    RREP(i,s.length()){
      if(ma>s[i]-'a'){
        FOR(j,s[i]-'a',s.length()){
          if(alpha[j]){
            string ans = s.substr(0,i);
            ans += (char)('a'+j);
            cout << ans << endl;
            return 0;
          }
        }
      }else{
        alpha[s[i]-'a'] = true;
        ma = max(ma,(ll)(s[i]-'a'));
      }
    }
  }
  REP(i,26){
    if(alpha[i]){
      char next = 'a'+i;
      cout << s << next << endl;
      break;
    }
  }
  return 0;
}


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

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());

			var dict = new Dictionary<string, int> {
				{ "AC", 0 },
				{ "WA", 0 },
				{ "TLE", 0 },
				{ "RE", 0 },
			};

			for (int i = 0; i < n; i++)
			{
				dict[Console.ReadLine()]++;
			}

			Console.WriteLine($"AC x {dict["AC"]}");
			Console.WriteLine($"WA x {dict["WA"]}");
			Console.WriteLine($"TLE x {dict["TLE"]}");
			Console.WriteLine($"RE x {dict["RE"]}");
		}
	}
}


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

string longestCommonSubsequence(string &s1, string &s2){

    int n = s1.size(), m = s2.size();
    // When building the answer, use the DP table itself
    // For each state check from which state we have arrived to the current state
    // If arrived from a diagonal state that means we need to include the
    // current character
    int dp[n+1][m+1];
    for(int i=0; i<=n; i++)
        dp[i][0] = 0;
    for(int j=0; j<=m; j++)
        dp[0][j] = 0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++){
            if(s1[i-1] == s2[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }

    // Now we need to build the actual answer
    // Start from last cell
    // and check from which cell we reached that cell

    string ans;
    int i = n, j = m;
    while(i>0 and j>0){
        if(dp[i][j] == dp[i-1][j])
            i--;
        else if(dp[i][j] == dp[i][j-1])
            j--;
        else{
            // That means we have reached here from diagonally so include the
            // current character
            ans.push_back(s1[i-1]);
            i--;
            j--;
        }
//        if(dp[i][j] == dp[i-1][j-1] + 1){
//            // That means we have reached here from diagonally so include the
//            // current character
//            ans.push_back(s1[i-1]);
//            i--;
//            j--;
//        }
//        else if(dp[i][j] == dp[i-1][j])
//            i--; // We have come here from the above row
//        else
//            j--;
    }

    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
 string s1, s2;
 cin>>s1>>s2;
 string ans = longestCommonSubsequence(s1, s2);
 cout<<ans;
 return 0;
}



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

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

/*さいころの面の数*/
const unsigned int FACE_SIZE = 6;

/*さいころの面の位置と、配列の番号の対応*/
enum FaceNumber{ TOP, SOUTH, EAST, WEST, NORTH, BOTTOM };

class Dice{
private:
	/*face[i]はi面の数字
	*iは{ TOP, SOUTH, EAST, WEST, NORTH, BOTTOM }のどれかを取る*/
	int face[FACE_SIZE];
	/*swapFace：引数で指定した順番にfaceを入れ替える関数*/
	void swapFace(int[FACE_SIZE]);
public:
	/*Dice():入力された6つの数値でfaceを初期化*/
	Dice();
	/*Dice::turn：commandで指定された方向にさいころを転がす*/
	void turn(char command);
	/*Dice::turn：指定された上面、全面になるようにさいころを転がす*/
	void turn(int, int);
	/*fNumで指定された面の数字を返す*/
	int getNumber(int fNum){ return face[fNum]; }
	/*指定された数字が、どの面にあるか返す*/
	int getLabel(int);
};

/*Dice():入力された6つの数値でfaceを初期化*/
Dice::Dice(){
	for (size_t i = 0; i < FACE_SIZE; i++)
	{
		std::cin >> face[i];
	}
}

/*swapFace：引数で指定した配列の順番にfaceを入れ替える関数
*配列の中身が{ WEST, SOUTH, TOP, BOTTOM, NORTH, EAST }なら、
*face[TOP]をface[WEST]に、face[SOUTH]はそのまま、face[EAST]をface[TOP]に・・・
*というように入れ替える
*参考： enum FaceNumber{ TOP, SOUTH, EAST, WEST, NORTH, BOTTOM }
*/
void Dice::swapFace(int* afterFace){
	int tmp[FACE_SIZE];									//変更前のさいころの面を保存する一時変数
	for (size_t faceNum = 0; faceNum < FACE_SIZE; faceNum++)
	{
		tmp[faceNum] = Dice::face[faceNum];
	}
	for (size_t faceNum = 0; faceNum < FACE_SIZE; faceNum++)
	{
		//faceNum面の数字を更新する
		int num = afterFace[faceNum];
		Dice::face[faceNum] = tmp[num];
	}
}

//commandで指定された方向にさいころを転がす
void Dice::turn(char command){
	if (command == 'E'){
		int afterFace[FACE_SIZE] = { WEST, SOUTH, TOP, BOTTOM, NORTH, EAST };
		Dice::swapFace(afterFace);
	}
	else if (command == 'N'){
		int afterFace[FACE_SIZE] = { SOUTH, BOTTOM, EAST, WEST, TOP, NORTH };
		Dice::swapFace(afterFace);
	}
	else if (command == 'S'){
		int afterFace[FACE_SIZE] = { NORTH, TOP, EAST, WEST, BOTTOM, SOUTH };
		Dice::swapFace(afterFace);
	}
	else if (command == 'W'){
		int afterFace[FACE_SIZE] = { EAST, SOUTH, BOTTOM, TOP, NORTH, WEST };
		Dice::swapFace(afterFace);
	}
	//z軸中心の右回転
	else if (command == 'R'){
		int afterFace[FACE_SIZE] = { TOP, WEST, SOUTH, NORTH, EAST, BOTTOM };
		Dice::swapFace(afterFace);
	}
}


//参考： enum FaceNumber{ TOP, SOUTH, EAST, WEST, NORTH, BOTTOM }
//commandで指定された方向にさいころを転がす
void Dice::turn(int top, int front){
	while (Dice::face[TOP] != top && Dice::face[SOUTH] != front){
		Dice::turn('N');
	}
	if (Dice::face[TOP] == top){
		while (Dice::face[SOUTH] != front){
			Dice::turn('R');
		}
	}
	else if (Dice::face[SOUTH] == front){
		while (Dice::face[TOP] != top){
			Dice::turn('W');
		}
	}
}

/*指定された数字が、どの面にあるか返す*/
int Dice::getLabel(int Num){
	int label;
	for (size_t i = 0; i < FACE_SIZE; i++)
	{
		if (Dice::face[i] == Num){
			label = i;
			break;
		}
	}
	return label;
}

int main(){
	Dice dice1 = Dice();
	int commands_size;
	int topNumber;
	int frontNumber;
	int topLabel;
	int frontLabel;


	std::cin >> commands_size;

	for (size_t i = 0; i < commands_size; i++)
	{
		std::cin >> topNumber >> frontNumber;

		dice1.turn(topNumber, frontNumber);
		std::cout << dice1.getNumber(EAST) << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int l = 0, r = 1e9;
    while(r - l > 1){
        int mid = (l + r) / 2;
        int now = 0, cnt = 1;
        rep(i, 0, n){
			if(a[i] > mid) cnt = INF;
			if(now + a[i] > mid){
				cnt++; now = a[i];
			}else{
				now += a[i];
			}
		}
		if(cnt > k) l = mid;
		else r = mid;
	}
	cout << r << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;
// vector<int> arr[100010],children[100010];
// int n,mod;
// pair<int,int> down[100010],up[100010];
// vector<pair<int,int>> downs[100010],pref[100010],suff[100010];
// pair<int,int> merge(pair<int,int> arr,pair<int,int>arr2)
// {
// 	int a=(arr.ff*arr2.ff)%mod;
// 	int b=(((arr.ss*(arr2.ff+arr2.ss))%mod)+arr.ff*arr2.ss)%mod;	
// 	return make_pair(a,b);
// }
// pair<int,int> process(pair<int,int> a)
// {
// 	return mp(a.ff,(a.ff+a.ss)%mod);
// }
// void dfs_one(int v,int par)
// {
// 	pair<int,int> res{1,0};

// 	for(auto itr:arr[v])
// 	{
// 		if(itr!=par)
// 		{
// 			//do something
// 			children[v].pb(itr);
// 			dfs_one(itr,v);
// 			res=merge(res,down[itr]);
// 			downs[v].pb(down[itr]);
// 		}
// 	}
// 	down[v]=process(res);
// }
// void dfs_two(int v,int par)
// {
// 	pair<int,int> res{1,0};
// 	for(int i=0;i<arr[v].size();i++)
// 	{

// 	}
// }

// cin>>n>>mod;
// 	for(int i=1;i<n;i++)
// 	{
// 		int x,y;
// 		cin>>x>>y;
// 		arr[x].pb(y);
// 		arr[y].pb(x);
// 	}

// 	dfs_one(1,-1);	

// 	// suffix sum and prefix sum
// 	for(int i=1;i<=n;i++)
// 	{
// 		pair<int,int> a{1,0};
// 		for(int j=0;j<downs[i].size();j++)
// 		{
// 			a=merge(a,downs[i][j]);
// 			pref.pb(a);
// 		}
// 		a={1,0};
// 		for(int j=(downs[i].size()-1);j>=0;j--)
// 		{
// 			a=merge(a,downs[i][j]);
// 			suff.pb(a);
// 		}
// 		reverse(all(suff));
// 	}
// 	dfs_two(1,-1);


// const int nax=2e5+5;
// vector<pair<int,int>> arr[nax];
	
	//https://leetcode.com/problems/word-ladder-ii/
	//https://leetcode.com/problems/sum-of-subarray-minimums/
	//https://leetcode.com/problems/subsets-ii/discuss/30168/C%2B%2B-solution-and-explanation	

	// int n,m;
	// cin>>n>>m;
	// for(int i=0;i<m;i++)
	// {
	// 	int a,b,c;
	// 	cin>>a>>b>>c;
	// 	arr[b].pb(mp(a,c));
	// }
	// for(int i=1;i<=n;i++)
	// {
		
	// }

signed main() {

	fastio();
//	#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	int N, M;
  cin >> N >> M;
  priority_queue<int > q;
 for(int i=0;i<N;i++){
    int a;
    cin >> a;
    q.push(a);
  }
 
  for(int i=0;i<M;i++){
    int a = q.top(); q.pop(); 
    q.push(a/2);
  }
 
  int ans = 0;
  for(int i=0;i<N;i++){
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
 	return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T>
struct BIT{
    private:
        vector<T> array;
        const int n;
    public:
        BIT(int _n) : array(_n + 1, 0), n(_n) {}
        // [1, i], i is 1-indexed
        T sum(int i){
            T s = 0;
            while(i > 0){
                s += array[i];
                i -= i & -i;
            }
            return s;
        }
        // [i, j), i and j are 1-indexed
        T sum(int i, int j){
            T ret_i = sum(i-1);
            T ret_j = sum(j);
            return ret_j - ret_i;
        }
        // i is 1-indexed
        void add(int i, T x){
            while(i <= n){
                array[i] += x;
                i += i & -i;
            }
        }

        // debug
        void print(){
            for(int i = 1; i < (int)array.size(); ++i){
                cout << sum(i, i+1) << " ";
            }
            cout << endl;
        }
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> sum(n+1, 0);
	rep(i,n){
		ll a;
		cin >> a;
		sum[i+1] = sum[i] + a - k;
	}
	vector<ll> cmp = sum;
	sort(cmp.begin(), cmp.end());
	cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
	BIT<ll> bit(n+5);
	ll ans = 0;
	rep(i,n+1){
		int idx = lower_bound(cmp.begin(), cmp.end(), sum[i]) - cmp.begin();
		ans += bit.sum(idx+1);
		bit.add(idx+1, 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7892
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [i64; n],
        b: [i64; n],
    }
    let mut b = b;
    let mut que = BinaryHeap::new();
    for i in 0..n {
        que.push((b[i], i));
    }
    let mut ans = 0;
    while let Some((x, idx)) = que.pop() {
        let y = b[(idx + 1) % n];
        let z = b[(idx + n - 1) % n];
        if y + z <= x - a[idx] {
            let q = (x - a[idx]) / (y + z);
            ans += q;
            b[idx] = x - q * (y + z);
            if b[idx] > a[idx] {
                que.push((b[idx], idx));
            }
        }
    }
    if a == b {
        puts!("{}\n", ans);
    } else {
        puts!("-1\n");
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

using namespace std;

int main(){
	string s; cin >> s;
	int nb=0;
	long long ans=0;
	for(auto c:s){
		if(c=='B'){
			nb++;
		}
		else{
			ans+=nb;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

int N, K;
int dp[101][100001];
int csum[100001];
int a[101];

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

  REP(i,N)cin >> a[i];

  REP(i,N+1)REP(j,K+1) dp[i][j] = 0;

  dp[0][0] = 1;

  FOR(i,1,N+1){

    csum[0] = dp[i-1][0];

    FOR(j,1,K+1)csum[j] = (csum[j-1]+dp[i-1][j]) % MOD;

    REP(j,K+1){
      if(j-a[i-1]-1 >= 0){
        dp[i][j] = csum[j] - csum[j-a[i-1]-1];
      }else{
        dp[i][j] = csum[j];
      }
      dp[i][j] %= MOD;
    }

  }

  if(dp[N][K] >= 0){
    cout << dp[N][K] << endl;
  }else{
    cout << dp[N][K] + MOD << endl;

  }

}

Measured memory_bytes: 40064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		String first = fs.next();
		String second = fs.next();
		
		int firstNum = fs.nextInt();
		int secondNum = fs.nextInt();
		
		String thrown = fs.next();
		
		if(thrown.equals(first)) {
			firstNum--;
		}else {
			secondNum--;
		}
		
		
		System.out.println(String.format("%d %d", firstNum, secondNum));
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 34364
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1, 105):
    for j in range(1, 105):
        for k in range(1, 105):
            v = i * i + j * j + k * k + i * j + j * k + k * i
            if v < 10050:
                ans[v] += 1

for i in range(n):
    print(ans[i + 1])

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

int main(){
    int n, x;
    cin >> n >> x;
    int min_ol = 1009, sum_ol = 0;
    for(int i=0; i<n; i++){
        int m;
        cin >> m;
        min_ol = min(min_ol, m);
        sum_ol+= m;
    }
    int count = 0;
    x -= sum_ol;
    while(x >= min_ol){
        x -= min_ol;
        count++;
    }
    cout << count + n << '\n';
    return 0;
}

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

typedef long long int ll;

int main()
{
    ll n, s = 0;
    cin >> n;
    vector<ll> a(n), x(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
        s += a[i];
    }

    x[0] = s;
    for(ll i = 1;i < n - 1;i += 2){
        x[0] -= 2 * a[i];
    }
    for(ll i = 0;i < n - 1;i++){
        x[i + 1] = 2 * a[i] - x[i];
    }

    for(ll i = 0;i < n;i++){
        cout << x[i]<<"\n";
    }

    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
void pk()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x,y,z,p;
    x=a*c;
    y=a*d;
    z=b*c;
    p=b*d;
    cout<<max(x,max(y,max(z,p)));

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //a #ifndef ONLINE_JUDGE 
    // freopen("/home/priyanshu/Hackercup/input.txt", "r", stdin); 
    // freopen("/home/priyanshu/Hackercup/output.txt", "w", stdout); 
    // #endif 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        pk();
    }
} 


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
int a[100],b[100];    
int main() {
	int n,i,j,k=0;
	while(cin >> n) {
       for (i=0;i<k;i++) if (a[i]==n) b[i]++; 
	   if (i==k) { a[k]=n; b[k]=1; k++; }
	}
	for (i=0;i<k;i++) for (j=0;j<i;j++) if (b[j]<b[j+1]) {swap(b[j],b[j+1]); swap(a[j],a[j+1]); }
	for (n=0; b[n]==b[0] && n<k;n++);
	for (i=0;i<n;i++) for (j=0;j<i;j++) if (a[j]>a[j+1]) swap(a[j],a[j+1]);
    for (i=0;i<n;i++) cout << a[i] << endl;
  	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i =(b)-1;i>=(a);--i)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	char ch;
	cin >> ch;
	cout << ch;
	
	cin >> ch;
	cout << ch;
	cin >> ch;
	cout << ch; 
	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#define TRUE (1)
#define FALSE (0)
#define UNKNOWN (2)

typedef struct {
    int power;
    int motor;
    int cable;
} CHECK;

CHECK queue[1000];
int head, tail;

void enq(CHECK t)
{
    queue[tail % 1000] = t;
    tail++;
}

void deq(CHECK *t)
{
    *t = queue[head % 1000];
    head++;
}

int main(void)
{
    int a, b, c, s, l;
    int n;
    int i;
    char quality[500];
    CHECK temp;
    
    while (1){
        scanf("%d%d%d", &a, &b, &c);
        
        s = a + b + c;
        
        if (s == 0){
            break;
        }
        
        for (i = 1; i <= s; i++){
            quality[i] = UNKNOWN;
        }
        
        scanf("%d", &n);
        
        head = tail = 0;
        
        for (i = 0; i < n; i++){
            scanf("%d%d%d%d", &temp.power, &temp.motor, &temp.cable, &l);
            if (l == TRUE){
                quality[temp.power] = quality[temp.motor] = quality[temp.cable] = TRUE;
            }
            else {
                enq(temp);
            }
        }
        
        while (head != tail){
            deq (&temp);
            if (quality[temp.power] == UNKNOWN && quality[temp.motor] == TRUE && quality[temp.cable] == TRUE){
                quality[temp.power] = FALSE;
            }
            else if (quality[temp.motor] == UNKNOWN && quality[temp.cable] == TRUE && quality[temp.power] == TRUE){
                quality[temp.motor] = FALSE;
            }
            else if (quality[temp.cable] == UNKNOWN && quality[temp.power] == TRUE && quality[temp.motor] == TRUE){
                quality[temp.cable] = FALSE;
            }
        }
        
        for (i = 1; i <= s; i++){
            printf("%d\n", quality[i]);
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
    do           \
    {            \
    } while (0)
#define dump(x) \
    do          \
    {           \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

struct edge
{
    int from, to;
    LL cost;
    edge(int from, int to, LL cost) : from(from), to(to), cost(cost) {}
};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr LL INF = 1LL << 50;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<edge> es;
    int a, b, c;
    REP(i, 0, m)
    {
        cin >> a >> b >> c;
        es.pb(a - 1, b - 1, -c);
    }
    VLL d(n, INF);
    VI prev(n, -1);
    d[0] = 0;
    REP(i, 0, n)
    {
        REP(j, 0, m)
        {
            int u = es[j].from;
            int v = es[j].to;
            LL cost = es[j].cost;
            if (d[v] > d[u] + cost)
            {
                d[v] = d[u] + cost;
                prev[v] = u;
            }
        }
    }

    vector<bool> visited(n, false);
    visited[n - 1] = true;
    int p = prev[n - 1];
    for (;;)
    {
        if (visited[p])
        {
            cout << "inf" << endl;
            return;
        }
        visited[p] = true;
        p = prev[p];
        if (p < 0)
            break;
    }

    REP(j, 0, m)
    {
        int u = es[j].from;
        int v = es[j].to;
        LL cost = es[j].cost;
        if (!visited[u])
            continue;
        if (d[v] > d[u] + cost)
        {
            cout << "inf" << endl;
            return;
        }
    }

    cout << -d[n - 1] << endl;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 256
import math
k = int(input())
s = 0
for p in range(1,k+1):
	for q in range(1,k+1):
		temp = math.gcd(p,q)
		for r in range(1,k+1):
			if r == 1:
				s += 1
			else:
				s = s + math.gcd(temp,r)
print(s)

Measured memory_bytes: 9184
from itertools import permutations
import math
N = int(input())
loc = [tuple(map(int, input().split())) for _ in range(N)]


def calc_dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2) ** 0.5


City = []
for i in range(N):
    City.append(i)
ans = 0
for root in permutations(City):
    st = -1
    for i, r in enumerate(root):
        if i == 0:
            stx, sty = loc[r]
        else:
            nx, ny = loc[r]
            ans += calc_dist(stx, sty, nx, ny)
            stx = nx
            sty = ny
print(ans/math.factorial(N))




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

int N;
int W;
long long w[110];
long long v[110];
long long dp[110][100010];

int main ()
{
    cin >> N >> W;
    for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
    //memset(dp, 0, sizeof(dp));
    for(int i = 0; i < 110; i++) for(int j = 0; j < 100010; j++) dp[i][j] = 1LL<<60;
    dp[0][0] = 0;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j <= 100010; j++)
        {
            if(j - v[i] >= 0)
            {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            }
            else
            {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    long long res = 0;
    for (int j = 0; j < 100010; j++)
    {
        if(dp[N][j] <= W) res = max(res, (long long)j);
    }
    cout << res << endl;
}

Measured memory_bytes: 86144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
using ll = long long;
int main() {
  ll n,k;
  ll sum=0;
  cin>>n>>k;
  int a[n];
  rep(i,n)a[i]=0;
  rep(i,k){
      int d;cin>>d;
      rep(j,d){
          int ad;cin>>ad;
          a[ad-1]++;
      }      
  }
  rep(i,n){
      if(a[i]==0)sum++;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3636
#encoidng utf-8

n = int(input())

for i in range(10):
    if 10**i > n:
        break
max_digit = i
# print(max_digit)
num_list = list("753")

def check(nums):
    value = False
    nums_list = list(str(nums))
    # print(nums)
    if (str(3) in nums_list) and (str(5) in nums_list) and (str(7) in nums_list):
        if nums <= n:
            value = True
            # print("::::clear")
    return value

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

#指定された桁数においてNより小さい数字の７５３を探す
def find_num(digit):
    count = 0
    for i in range(1,3**(digit)):

        pre_3 = Base_10_to_n(i,3)
        pre_3 = int(pre_3)
        # print(type(pre_3))
        meta='{0:0'+str(digit)+'d}'
        pre_3 = meta.format(pre_3)
        # print(pre_3)
        pre_3_list = list(pre_3)
        predict_num = []
        # print(pre_3_list)1234
        for i in range(len(pre_3_list)):
            if pre_3_list[i] == "0":
                predict_num.append("3")
            elif pre_3_list[i] == "1":
                predict_num.append("5")
            else:
                predict_num.append("7")
        # print("".join(predict_num))
        nums_pre = "".join(predict_num)
        if check(int(nums_pre)):
            count += 1
    return count

count = 0
for i in range(3,max_digit+1):
    count += find_num(i)
print(count)


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

using namespace std;

int main(){
    int h,n;
    cin >> h >> n;
    int a = 0;
    for(int i=0;i<n;++i){
        int t;
        cin >> t;
        a += t;
    }
    cout << (a >=h ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		long[] array = new long[3 * N];
		for(int i = 0; i < 3 * N; i++){
			array[i] = sc.nextLong();
		}
		
		Arrays.sort(array);
		
		long answer = 0;
		for(int i = 0; i < 3 * N; i++){
			final int fst = i;
			final int lst = (3 * N - 1) - 2 * i;
			final int mid = lst - 1;
			
			//System.out.println(fst + " " + mid + " " + lst);
			
			if(fst >= mid){ break; }
			answer += array[mid];
		}
		
		System.out.println(answer);
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 60816
<?php

while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%d %d', $n, $x);

    if ($n === 0 && $x === 0) {
        break;
    }

    $result = array();
    for ($i = 1; $i <= $n; $i++) {
        for ($j = $i + 1; $j <= $n; $j++) {
            if ($i + $j >= $x) {
                break;
            }

            $k = $x - $i - $j;

            if ($k <= $n && $k > 0 && $k !== $j && $k !== $i) {
                $arr = array($i, $j, $k);
                sort($arr);
                $str = implode(',', $arr);
                if (!in_array($str, $result)) {
                    $result[] = $str;
                }
            }
        }
    }

    echo count($result), PHP_EOL;
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    if (s == t.substr(0, s.size()))
        cout << "Yes" << ln;
    else 
        cout << "No" << ln;
    return 0;
}


Measured memory_bytes: 3644
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A = sorted(A, key=lambda x:x[0])
ans = 0
num = 0
for i in range(N):
    if num + A[i][1] < M:
        ans += A[i][0] * A[i][1]
        num += A[i][1]
    else:
        s = M - num
        ans += A[i][0] * s
        break
print(ans)

Measured memory_bytes: 29796
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
// #define vb          vector<bool>
// #define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
// #define ub(x)       upper_bound(x)
// #define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("b1.in","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N            1e5+5
#define PRIME           1000000007
#define MAX         50000
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define pi          3.14159265358979323
int i,j,k;
// int n;
// const int N=1e6+5;
// vector<bool> prime(N);
// void sieve(){
//     for(int i=0;i<=N;i++)prime[i]=true;
//     prime[0]=prime[1]=false;
//     for(int i=2;i*i<=N;i++){
//         if(prime[i] and i*i<=N){
//             for(int j=i*i;j<=N;j+=i){
//                 prime[j]=false;
//             }
//         }
//     }
// }
// const int N=1e3+5;
// int a[N];


void Anon_mouS(){
    int r,g,b;
    cin>>r>>g>>b>>k;
    //b>g>r
    while(k>0 and g<=r)g*=2,k--;
    while(k>0 and b<=g)b*=2,k--;
    if(b>g and g>r)cout<<"Yes";
    else cout<<"No";
}
int32_t main(){
    fastio;
    int q=1;
    // sieve();
    // cin>>q;
    for(int it=1;it<=q;it++){
        // cout<<"Case #"<<it<<": ";
        Anon_mouS();
    }
    return 0;   
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,x,z;
    scanf("%d %d",&k,&x);
    for(int i=x-k+1;i<=x;i++)
        printf("%d ",i);
    for(int i=x+1;i<=x+k-1;i++)
        printf("%d ",i);
    return 0;
}



Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline())
S = [int(x) for x in sys.stdin.readline().split()]
q = int(sys.stdin.readline())
T = [int(x) for x in sys.stdin.readline().split()]

count = 0
for t in T:
    for s in S:
        if s == t:
            count += 1
            break

print(count)


Measured memory_bytes: 6592
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    int n=s.length();
    int l=70;
    int[][] next=new int[l+1][n];
    for(int i=0;i<n;i++){
      next[0][i]=i+(s.charAt(i)=='L'?-1:1);
    }
    for(int i=1;i<=70;i++){
      for(int j=0;j<n;j++){
        next[i][j]=next[i-1][next[i-1][j]];
      }
    }
    int[] ans=new int[n];
    for(int i=0;i<n;i++){
      ans[next[l][i]]++;
    }
    for(int i=0;i<n-1;i++){
      System.out.print(ans[i]+" ");
    }
    System.out.println(ans[n-1]);
  }
}

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

int E[300010], W[300010];

int main(){
  int N;
  cin >> N;
  
  char S[N];
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }
  
  for(int i = 0; i < N; i++){
    if(S[i] == 'E') E[i] = 1;
    else W[i] = 1;
  }
  
  for(int i = 1; i < N; i++){
	E[i] += E[i-1];
    W[i] += W[i-1];
  }
  
  int mn = 10000000;
  for(int i = 0; i < N; i++){
    int sum = 0;
    if(i) sum += W[i-1];
    sum += E[N-1] - E[i];
    mn = min(mn, sum);
  }
  
  cout << mn << endl;
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

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

  ll n;
  cin >> n;
  string s;
  cin >> s;
  if (s.length() % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  rep(i, s.length()/2) {
    if(s[i] != s[s.length()/2+i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

#define allof(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 998244353;
const ll MAXN = 3e5 + 5;

ll N, A, B, K;
ll fact[MAXN];

ll qpow(ll x, ll y){
    ll ans = 1;
    while(y){
        if(y & 1){
            ans = ans * x % mod;
        }

        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}

ll nck(ll n, ll k){
    return fact[n] * qpow(fact[k], mod - 2) % mod * qpow(fact[n - k], mod - 2) % mod;
}

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    fact[0] = 1;
    for(int a = 1; a < MAXN; a++){
        fact[a] = fact[a - 1] * a % mod;
    }

    cin >> N >> A >> B >> K;

    ll ans = 0;
    for(int a = 0; a <= N; a++){
        ll remain = K - a * A;
        if(remain % B != 0){
            continue;
        }
        ll numB = remain / B;
        if(numB < 0 || numB > N){
            continue;
        }

        ll tmp = nck(N, a) * nck(N, numB) % mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans;
}


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

fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val (n, k) = longList()
    val p = intList().map { it - 1 }
    val c = longList()
    val maps = mutableListOf<Map<Int, Long>>()
    var m = Long.MIN_VALUE
    repeat(n.toInt()) { i ->
        var index = i
        val route = maps.find { it.containsKey(p[index]) } ?: run {
            val map = hashMapOf<Int, Long>()
            while (true) {
                val next = p[index]
                if (map.containsKey(next)) {
                    map[-1] = map.values.sum()
                    maps.add(map)
                    break
                } else {
                    index = next
                    map[next] = c[index]
                }
            }
            map
        }
        val routeSize = route.keys.size - 1
        val loop = (k - 1) / routeSize
        val seed = (route[-1] ?: 0) * loop
        if (seed > 0) {
            val remain = ((k - 1) % routeSize).toInt() + 1
            var score = 0L
            index = i
            repeat(remain) {
                val next = p[index]
                index = next
                score += c[index]
                m = max(seed + score, m)
            }
            m = max(seed + score, m)
        } else {
            var score = 0L
            index = i
            repeat(min(k.toInt(), routeSize)) {
                val next = p[index]
                index = next
                score += c[index]
                m = max(score, m)
            }
            m = max(score, m)
        }
    }
    println(m.toString())
}


Measured memory_bytes: 50480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

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


int main(){
    ll n, x;
    cin >> n >> x;
    ll ans=0;
    ll temp=0;
    //一旦最初の入力とスタートの距離をansにし、入力ごとに最大公約数に更新していく
    cin >> temp;
    ans = abs(temp-x);

    for(int i=1; i<n; i++){
        cin >> temp;
        ans = gcd(ans,abs(temp-x));
    }
    cout << ans << endl;




}

Measured memory_bytes: 3576
import string
S = input()
N = len(S)

for i in range(N):
    if i < N-1 and S[i] == S[i+1]:
        print(i+1, i+2)
        quit()
    elif i < N-2 and S[i] == S[i+2]:
        print(i+1, i+3)
        quit()
print(-1, -1)


Measured memory_bytes: 4084
import sys
readline = sys.stdin.readline

import numpy as np
import math

N,W = map(int,readline().split())

dp = np.array([10 ** 12 + 1] * (10 ** 5 + 1), dtype = int)
dp[0] = 0

for i in range(N):
  w,v = map(int,readline().split())
  np.minimum(dp[:-v] + w,dp[v:],out = dp[v:])
  
for i in range(len(dp) - 1,-1,-1):
  if dp[i] <= W:
    print(i)
    break

Measured memory_bytes: 28192