akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

// all_of
// partial_sum, adjacent_difference

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#endif

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

template<class Pair>
struct CompBySecond {
	bool operator()(const Pair& left, const Pair& right) {
		return left.second < right.second || (left.second == right.second && left.first < right.first);
	}
};

int H, W;
string S[10000];

char SS(int i, int j) {
	if (!INSIDE(i, j, H, W)) return '.';
	return S[i][j];
}

void R(int i, int j) {
	int sum = 0;
	REP(a, -1, 2) {
		REP(b, -1, 2) {
			if (a == 0 && b == 0)continue;
			sum += SS(i + a, j + b) == '#';
		}
	}
	S[i][j] = '0' + sum;
}

int main() {
	cin >> H >> W;
	REP(i, 0, H) {
		cin >> S[i];
	}
	REP(i, 0, H) {
		REP(j, 0, W) {
			if (S[i][j] == '#') continue;
			R(i, j);
		}
	}
	REP(i, 0, H) {
		cout << S[i] << endl;
	}
	return 0;
}



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

using namespace std;

int main(){
    int N,D,count=0;
    cin >> N >> D;
    for(int i=0;i<N;i++){
        double x,y;
        cin >> x >> y;
        double d =sqrt((x*x) + (y*y));
        if(d<=D)count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3696
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := range graph {
		for j := range graph[i] {
			if j == n-1 {
				fmt.Printf("%d\n", graph[i][j])
			} else {
				fmt.Printf("%d ", graph[i][j])
			}
		}
	}
}



Measured memory_bytes: 1204
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n <= m then  List.range n `To m else []
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (0 ++^ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv
let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv
let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'
let itoa n = Char.chr (n + Char.code '0')

let between n x m = n <= x && x < m


(* ===== MAIN ===== *)

let x, n = scan "%d %d" (fun x n -> x, n)
let ps = if n > 0 then scan_list ~sep:' ' int_of_string |> List.sort compare else []

let can = Array.init 102 (fun i -> i)
let () = List.iter (fun p -> can.(p) <- max_int/10) ps

let ()=
  let ans =
    can
    |> Array.to_list
    |> List.map (fun a -> (abs (a-x), a))
    |> List.sort (fun (a1, o1) (a2, o2) ->
         if a1 = a2 then compare o1 o2
         else compare a1 a2)
  in
    Printf.printf "%d\n" @@ snd @@ List.hd ans


Measured memory_bytes: 5476
w = ["Wednesday", "Thursday", "Friday",
     "Saturday", "Sunday", "Monday", "Tuesday"]
a = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
while 1:
    m, d = map(int, input().split())
    if m == 0:
        break
    s = 0
    for i in range(m - 1):
        s += a[i]

    print(w[(s+d) % 7])



Measured memory_bytes: 5592
# self.author = Fuad Ashraful Mehmet ,CSE-UAP

from sys import stdin
input=stdin.readline


def fun():
    n=int(input())
    ans=n*(n**2+3*n+2)//6

    for _ in range(n-1):
        a,b=map(int,input().split())

        if a>b:
            a,b=b,a
        ans-=a*(n-b+1)
    print(ans)

fun()

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

using namespace std;

int main()
{
    int totalValueOfShares;  //target sum
    int size; // number of coin types
    
    cin >> totalValueOfShares >> size;
    
    vector<int> numOfShares(size);
    vector<int> values(totalValueOfShares + 1);
    
    for(int i = 0; i < size; i ++){
        cin >> numOfShares[i];
    }
    
    values[0] = 0;
    
    int minValue = 0x7FFFFFFF;
    
   

            for (int i = 0; i < size; i ++)
            {
                if (numOfShares[i] < minValue)
                {
                    minValue = numOfShares[i];
                }
            }

            for (int i = 1; i <= totalValueOfShares; i++)
            {
                values[i] = 0x7FFFFFFF;
            }


            for (int i = minValue; i <= totalValueOfShares; i++)
            {
                for (int j = 0; j < size; j++)
                    if (numOfShares[j] <= i)
                    {
                        int sum = values[i - numOfShares[j]];
                        if (sum < 0x7FFFFFFF && sum + 1 < values[i])
                            values[i] = sum + 1;
                    }
            }
            if (values[totalValueOfShares] == 0x7FFFFFFF)
            {
                cout <<  0;
            }
            cout << values[totalValueOfShares] << "\r\n";    
    
    

    
}


Measured memory_bytes: 3200
fn main() {
    let (a, b): (usize, usize) = (read::<usize>(), read::<usize>());
    if a <= b {
        println!("unsafe",);
    } else {
        println!("safe",);
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

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

// =========


Measured memory_bytes: 2132
#include <stdio.h>

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(1){
		c-=b;
		if(c<=0){
			puts("Yes");
			return 0;
		}
		a-=d;
		if(a<=0){
			puts("No");
			return 0;
		}
	}
}


Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn = 20 + 10;
const int inf = 0x3f3f3f3f;

int read()
{
	int x;
	scanf("%d", &x);
	return x;
}

int n, v[maxn], c[maxn], x, y, ans, f[maxn];

bool cmp(int x, int y)
{
	return x > y;
}

int main()
{
	n = read();
	for(int i = 1; i <= n; i ++)
	{
		v[i] = read();
	}
	for(int i = 1; i <= n; i ++)
	{
		c[i] = read();
		f[i] = v[i] - c[i];
	}
	sort(v + 1, v + n + 1, cmp);
	sort(c + 1, c + n + 1, cmp);
	
	for(int i = 1; i <= n; i ++)
	{
		if(f[i] > 0)ans += f[i];
	}
	
	cout << ans << endl;
}

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

int main(){
    int n;
    cin>>n;
    int a[n],i;
    for(i=0;i<n-1;i++)cin>>a[i];
    int s[n]={0};
    for(i=0;i<n-1;i++){
    	s[a[i]-1]++;
	}
	for(i=0;i<n;i++)cout<<s[i]<<endl;
	return 0;
}


Measured memory_bytes: 5212
import itertools


def count_black(row, col):
    count = 0
    for i, x in enumerate(row):
        for j, y in enumerate(col):
            if x == 0 and y == 0:
                if C[i][j] == "#":
                    count += 1
    return count


if __name__ == "__main__":
    H, W, K = [int(x) for x in input().split(" ")]
    C = []
    for _ in range(H):
        c = [s for s in input()]
        C.append(c)
    # print(C)
    ans = 0
    for row in itertools.product([0, 1], repeat=H):
        for col in itertools.product([0, 1], repeat=W):
            if count_black(row, col) == K:
                ans += 1
    print(ans)


Measured memory_bytes: 68488
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int a,b;
    cin >> a >> b;
    if(a%3 == 0 || b%3 == 0||(a+b)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll zero = 0;
ll INF = 10000000000;

int main(void){
    string S;
    cin >> S;
    vector<int> s;
    bool RL = false;
    int cnt = 0;
    for(char i: S){
        if( (i == 'R') ^ RL ){
            cnt++;
        }
        else{
            s.push_back(cnt);
            cnt = 1;
            RL = !RL;
        }
    }
    s.push_back(cnt);
    
    int len = s.size();
    
    for(int i = 0; i < len/2; i++){
        for(int j = 0; j < s.at(2*i)-1; j++){
            printf("%d ", 0);
        }
        printf("%d ", (s.at(2*i) + 1)/2 + s.at(2*i+1)/2 );
        printf("%d ", s.at(2*i)/2 + (s.at(2*i+1) + 1)/2 );
        for(int j = 0; j < s.at(2*i+1)-1; j++){
            printf("%d ", 0);
        }
    }
    
    
}


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

using namespace std;
const int N = 1e5 + 5;
int num[N], n, a, ans;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	while (n--) {
		cin >> a;
		a++;
		num[a + 1]++;
		num[a]++;
		num[a - 1]++;
	}
	for (int i = 0; i < N; i++)
	{
		ans = max(ans, num[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

 int main(){
     int N,K,l[51],sum=0;
     cin>>N>>K;
     for(int i=0;i<N;i++) cin>>l[i];
     sort(l,l+N,greater<int>());
     
     rep(i,K) sum+=l[i];

    p(sum);
 }

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <climits>
#include <utility>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#define REP(i,n) for(int (i)=0;i<(int)(n);++(i))
#define REPIT(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define PB push_back
#define FT first
#define SD second
#define ZERO(x) memset(x,0,sizeof(x))
#define NEG(x) memset(x,-1,sizeof(x))
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define OIII(x,y,z) printf("%d %d %d\n",(x),(y),(z))
#define OII(x,y) printf("%d %d\n",(x),(y))
#define OI(x) printf("%d\n",(x))
#define OL(x) cout<<(x)<<endl
#define OLL(x,y) cout<<(x)<<" "<<(y)<<endl
#define OLLL(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define RS(s) scanf("%s",(s))
#define MP(x,y) make_pair((x),(y))
#define SZ(x) ((int)(x).size())
#define FIN(f) freopen(f,"r",stdin)
#define FOUT(f) freopen(f,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<int,int> PII;
const int MOD = 1e9+7;
const int maxn = 222222;
int n;
int a[maxn];
int main(int argc, char const *argv[])
{
    RI(n);
    REP(i,n) RI(a[i]);
    LL ans = 0;

    for(int i=0;i<n-1;++i) {
        ans += a[i] / 2;
        a[i] %= 2;
        if(a[i+1] > 0 && a[i] > 0) {
            ans ++;
            a[i+1]--;
        }
    }
    ans += a[n-1] / 2;
    OL(ans);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, m, awa = 0, aac = 0; cin >> n >> m;
	vector<bool>is_ac(n, false);
	vector<int>wa(n, 0);
	for (int i = 0; i < m; i++) {
		int p; string s; cin >> p >> s; p--;
		if (!is_ac[p]) {
			if (s[0] == 'A') {
				is_ac[p] = true;
				aac += 1;
				awa += wa[p];
			} else {
				wa[p]++;
			}
		}
	}
	cout << aac << " " << awa << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
         
        while(h != 0 || w != 0){
 
            StringBuilder sb = new StringBuilder();
 
            for(int i = 0; i < h; i++){
 
                for(int j = 0; j < w; j++){
                    if(j == 0 || j == w - 1 || i == 0 || i == h - 1){
                        sb.append("#");
                    }else{
                        sb.append(".");
                    }
                }
                sb.append("\n");
 
            }
            System.out.println(sb);
 
            h = sc.nextInt();
            w = sc.nextInt();
        }
    }
}

Measured memory_bytes: 27476
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] S = new String[W.length()];
		for(int i=0;i<W.length();i++){
			S[i] = String.valueOf(W.charAt(i));
		}

		boolean flg = true;
		for(int i=0,k=S.length-1;i<S.length;i++,k--){
			if(i>=k){
				break;
			}
			if(S[i].equals(S[k])){

			}else{
				flg = false;
				break;
			}

		}
		for(int i=0,k=((S.length-1)/2)-1;i<S.length;i++,k--){
			if(i>=k){
				break;
			}
			if(S[i].equals(S[k])){

			}else{
				flg = false;
				break;
			}

		}

		for(int i=((S.length+3)/2)-1,k=S.length-1;i<S.length;i++,k--){
			if(i>=k){
				break;
			}
			if(S[i].equals(S[k])){

			}else{
				flg = false;
				break;
			}

		}
		String ans ;
		if(flg){
			ans = "Yes";
		}else{
			ans = "No";
		}
		System.out.println(ans);
	}


}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define int         long long
#define io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define mi          map<int,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        '\n'
#define hell        1000000007
using namespace std;
void solve()
{
    int n;
    cin>>n;
    vector<int> d(200005);
    bitset<4000007> dp;
    
    int sum=0;
    dp[0]=1;
    for(int i=1;i<=n;i++)
    {
        cin>>d[i];
        sum+=d[i];
        dp |=dp <<d[i];
    }
    int odd=sum%2;
    for(int i=sum/2 +odd;i<4000007;i++)
    {
        if(dp[i])
        {
            cout<<i;
            return;
        }
    }
}
signed main(){
    io;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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



const int N = 1e5 + 5;




int n, m, x, y, a[N], b[N];
pair < int, int > ans[N];
vector < int > g[N], order;
bool used[N];

void dfs(int v){
    used[v] = true;
    for(int to : g[v]){
        if(!used[to]){
            dfs(to);
        }
    }
    order.push_back(v);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n + m - 1; i++){
        cin >> x >> y;
        g[x].push_back(y);
    }
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            dfs(i);
        }
    }
    reverse(order.begin(), order.end());
    ans[order[0]] = make_pair(0, 0);
    for(int i = 0; i < (int)order.size(); i++){
        a[order[i]] = i + 1;
        b[i + 1] = order[i];
    }
    for(int i = 0; i < (int)order.size(); i++){
        for(int to : g[order[i]]){
            ans[to] = max(ans[to], make_pair(a[order[i]], order[i]));
        }
    }
    for(int i = 1; i <= n; i++){
        cout << ans[i].second << "\n";
    }
}


Measured memory_bytes: 11640
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    string s;
    cin >> s;

    bool ans = true;

    if (s.size() % 2 == 1) {
        ans = false;
    } else {
        int ro = s.size() / 2;
        for (int i = 0; i < ro; i++) {
            if (!(s[i * 2] == 'h' && s[i * 2 + 1] == 'i')) {
                ans = false;
                break;
            }
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
	int N; cin >> N;
	for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

	// 初期化は既に 0 に初期化される
	// 初期条件も既に 0 で OK

	// ループ
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				if (j == k) continue;
				chmax(dp[i + 1][j], dp[i][k] + a[i][j]);
			}
		}
	}

	// 答え
	long long res = 0;
	for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
	cout << res << endl;
}

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

using namespace std;
	
const int maxn=1e5*3+20;
int b[maxn];

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

 



Measured memory_bytes: 640
n=int(input())
x,l=[0]*n,[0]*n
xlr=[[0]*2 for i in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  x[i],l[i]=a,b
  xlr[i]=[a-b,a+b]
xlr.sort()
cnt=0
chk=xlr[n-1][0]
for i in range(2,n+1):
  if chk<xlr[n-i][1]:
    cnt+=1
  else:
    chk=xlr[n-i][0]
print(n-cnt)

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

int main() {
  long n;
  cin >> n;
  int data = 1000000;
  
  for(int i = 1; i <= sqrt(n); i++) {
    if(n % i == 0) {
      long k = n / i;
      int count = 0;
      while(k > 0){
        k /= 10;
        count ++;
      }
      if(data >= count) {
        data = count;
      }
    }
  }
  cout << data << endl;
}

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

using namespace std;

struct packet {
    int time, src, dst;
};

bool operator<(const packet& a, const packet& b)
{
    return a.time<b.time;
}

int main()
{
    int n, m;
    while(cin >> n >> m, n|m)
    {
        set<int> infected;
        infected.insert(1);
        packet ps[m];
        for(int i=0; i<m; i++)
        {
            cin >> ps[i].time >> ps[i].src >> ps[i].dst;
        }
        sort(ps, ps+m);
        for(int i=0; i<m; i++)
        {
            if(infected.find(ps[i].src)!=infected.end())
            {
                infected.insert(ps[i].dst);
            }
        }
        cout << infected.size() << endl;
    }

}

Measured memory_bytes: 4244
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    int l;
    vector<int> ls;
    for (int i = 0; i < N; i++) {
        cin >> l;
        ls.push_back(l);
    }
    sort(ls.begin(), ls.end(), greater<int>());
    cout << accumulate(ls.begin(), ls.begin() + K, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int cal(int e) {
	int m = 2000000000, x;
	for (int z = 0; z * z * z <= e; z++) {
		for (int y = 0; z * z * z + y * y <= e; y++) {
			x = e - y * y - z * z * z;
			if (x < 0)break;
			m = min(m, x + y + z);
		}
	}
	return m;
}

int main() {
	vector<int> a;
	int hoge;
	while (1) {
		cin >> hoge;
		if (hoge != 0) {
			a.push_back(hoge);
		}
		else break;
	}
	for (int i = 0; i != a.size(); i++) {
		cout << cal((int)a[i]) << endl;
	}
	return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cerr << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define X first
#define Y second
#define pb push_back
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define vi vector<int>
#define vii vector<vector<int>>

int32_t main(){ fast;
	int x; cin>>x;
	cout<<(x >= 30 ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#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 ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

const int INF = 1e9;

int main(void)
{
	cin.sync_with_stdio(false);
	int N, M;
	cin >> N >> M;

	vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF));
	dp[0][0] = 0;

	REP(m, M) {
		int A, B;
		cin >> A >> B;
		unsigned int mask = 0;
		REP(b, B) {
			int c;
			cin >> c;
			--c;
			mask |= (1 << c);
		}

		REP(before, 1 << N) {
			dp[m + 1][before] = min(dp[m + 1][before], dp[m][before]);
			auto after = before | mask;
			if (dp[m][before] != INF) {
				dp[m + 1][after] = min(dp[m + 1][after],
					dp[m][before] + A);
				//cerr << "dp = " << dp[m + 1][after] << endl;
			}
		}

		//cerr << "dp:::" << endl;
		//REP(before, 1 << N) {
		//	cerr << dp[m + 1][before] << endl;
		//}

	}

	if (dp[M][(1 << N) - 1] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << dp[M][(1 << N) - 1] << endl;
	}

	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = fs.nextInt();
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 0) {
                ans += a[i] / 2;
//                System.out.println("i = " + i + ": " + a[i] / 2);
            } else {
                if (a[i] != 1) {
                    ans += a[i] / 2;
                }
                if (i + 1 < n && a[i + 1] > 0) {
                    a[i + 1]--;
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 9728
from itertools import accumulate
from bisect import bisect_right

N, M, K = [int(n) for n in input().split()]
A = [0]+[*accumulate([int(n) for n in input().split()])]
B = [*accumulate([int(n) for n in input().split()])]
ans = 0
a = bisect_right(A, K)
for i in range(a):
    b = bisect_right(B, K-A[i])
    ans = max(ans, i+b)
print(ans)


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

struct edge {
  int cur, to, dist, cost, idx;
};
typedef vector< vector< edge > > Graph;

vector< const edge* > Dijkstra(const Graph& graph) {
  typedef pair< int, int > Pi;
  typedef pair< Pi, int > Pii;
  const int INF = 1 << 30;
  vector< Pi > min_cost(graph.size(), Pi(INF, INF));
  vector< const edge* > prev(graph.size(), (edge *)NULL);
  min_cost[0] = make_pair(0, 0);
  priority_queue< Pii, vector< Pii >, greater< Pii > > que;
  que.push(make_pair(make_pair(0, 0), 0));
  while(!que.empty()) {
    Pii p = que.top(); que.pop();
    if(min_cost[p.second] < p.first) continue;
    for(int i = 0; i < graph[p.second].size(); i++) {
      const edge& e = graph[p.second][i];
      if(min_cost[e.to] <= make_pair(min_cost[p.second].first + e.dist, e.cost)) continue;
      min_cost[e.to] = make_pair(min_cost[p.second].first + e.dist, e.cost);
      prev[e.to] = &graph[p.second][i];
      que.push(make_pair(min_cost[e.to], e.to));
    }
  }
  return(prev);
}

int main()
{
  int N, M;
  while(cin >> N >> M, N) {
    Graph graph(N);    
    for(int i = 0; i < M; i++) {
      int u, v, d, c;
      cin >> u >> v >> d >> c;
      --u, --v;
      graph[u].push_back((edge){u, v, d, c, i});
      graph[v].push_back((edge){v, u, d, c, i});
    }
    vector< const edge* > prev = Dijkstra(graph); // 使った辺へのポインタ
    vector< bool > killed(M, false);
    int ret = 0;
    for(int i = 1; i < N; i++) {
      const edge* now = prev[i];
      while(now != (const edge*)NULL && !killed[now -> idx]) {
        killed[now -> idx] = true;
        ret += now -> cost;
        now = prev[now -> cur];
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 2784
#include<cstdio>
const int N = 1e5+5;
int p[N];
int vis[N];

int get(int u){
    if(p[u]==u) return u;
    else return p[u] = get(p[u]);
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) vis[i] = 0, p[i] = i;
    while(m--){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        int x = get(u), y = get(v);
        p[x] = y;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int x = get(i);
        if(!vis[x]){
            ans++;
            vis[x] = 1;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1408
import Data.List
import Control.Applicative

judge :: [String] -> [Int]
judge [t, h]
    | t > h  = [3, 0]
    | t == h = [1, 1]
    | t < h  = [0, 3]

main = do
    _ <- getLine
    putStrLn =<< (unwords . map show . map sum . transpose . map judge . map words . lines) <$> getContents

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll x,y; cin >> x >> y;
    ll res = 0;
    while(x <= y){
        x*= 2;
        res++;
    }
    out(res);
}


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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back

const int N = 100005;

void solve() {
	int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
	cin >> n >> k;
	int a[n];
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	int dp[k + 1];
	dp[0] = 0;
	for (i = 0; i <= k; i++) {
		ans = 1;
		for (j = 0; j < n; j++) {
			if (i - a[j] >= 0) {
				ans = (ans & dp[i - a[j]]);
			}
		}
		dp[i] = !(ans);
	}
	if (dp[k]) {
		cout << "First";
	}
	else {
		cout << "Second";
	}
	return ;
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// int t; cin >> t; while (t--)
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <list>
#include <string>
#include <stack>
#include <utility>
#include <cstdio>

using namespace std;

struct Water {
    int b;
    int e;
    int area;
};

class PredFunctor {
  public:
    int b;
    int* area_ptr;
  public:
    PredFunctor(int b, int *area_ptr) : b(b), area_ptr(area_ptr) { }
    bool operator()(const Water& water) {
        if (water.b > this->b) {
            *area_ptr += water.area;
            return true;
        }
        return false;
    }
};

int main(void) {

    string map;
    cin >> map;

    int total_area = 0;
    list<Water> waters;
    stack<int> geo;
    for (int i = 0; i < map.size(); ++i) {
        switch (map[i]) {
            case '\\':
                geo.push(i);
                break;
            case '_':
                // do nothing
                break;
            case '/':
                if ( ! geo.empty()) {
                    int this_area = i - geo.top();
                    total_area += this_area;
                    PredFunctor pred(geo.top(), &this_area);
                    waters.remove_if(pred);
                    waters.push_back({ geo.top(), i, this_area });
                    geo.pop();
                }
                break;
            default:
                fprintf(stderr, "unknown character: %c\n", map[i]);
                return 1;
        }
    }

    printf("%d\n", total_area);
    printf("%lld", waters.size());
    for (list<Water>::iterator it = waters.begin();
            it != waters.end(); ++it) {
        printf(" %d", it->area);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	priority_queue<int> pq;
	rep(i,n){
		int a;cin >> a;
		pq.push(a);
	}
	rep(i,m){
		int a = pq.top();pq.pop();
		a /= 2;
		pq.push(a);
	}
	ll ans = 0;
	while(!pq.empty()){
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
}


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

using namespace std;

int main()
{
  int N, M, A[1000];

  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> A[i];


  int now = 0, flag = false, sum = 0;
  vector< int > vs;
  while(!flag || now != 0) {
    int aa = 114514, bb = -114514;
    for(int i = 0; i < M; i++) {
      aa = min(aa, A[now]);
      bb = max(bb, A[now]);
      now = (now + 1) % N;
    }
    sum += bb - aa;
    flag = true;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3096
N,x=map(int,input().split())
a=list(map(int,input().split()))
man=[0]*N
a.sort()
ans=0
for i in range(N):
    if a[i]<=x:
        x-=a[i]
        a[i]=0
        ans+=1
    else:
        break
if ans==N:
    if x!=0:
        ans-=1
if ans<0:
    ans=0
print(ans)


Measured memory_bytes: 8960
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

A, B = LI()
print((A+B)//2 if (A+B)%2==0 else "IMPOSSIBLE")

Measured memory_bytes: 39152
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto G = new long[][](N);
    foreach (i; 0 .. M)
    {
        long a, b;
        scan(a, b);
        a--, b--;
        G[a] ~= b;
        G[b] ~= a;
    }
    auto ans = new long[](N);
    ans[] = -1;
    ans[0] = 0;
    DList!long Q;
    Q.insertBack(0);
    while (!Q.empty)
    {
        long v = Q.front;
        Q.removeFront();
        dprint(v, G[v]);
        foreach (w; G[v])
        {
            dprint(ans[w]);
            if (ans[w] == -1)
            {
                ans[w] = v;
                Q.insertBack(w);
            }
        }
    }
    writeln("Yes");
    foreach (a; ans[1 .. $])
        writeln(a + 1);
}


Measured memory_bytes: 26284
X = int(input())
dp = [1]+[0]*X
if X<100:
    print(0)
    exit()
for i in range(100,X+1):
    if 100 <= i <= 105:
        dp[i] = 1
    elif sum(dp[i-105:i-99]) >= 1:
        dp[i] = 1
if dp[X] == 1:
    print(1)
else:
    print(0)


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200000 + 1000;
int e, Begin[Maxn], To[Maxn], Next[Maxn];
int N, M, Q;
inline void add_edge(int x, int y)
{
	To[++e] = y;
	Next[e] = Begin[x];
	Begin[x] = e;
}
struct query
{
	int x, y, z;
}A[Maxn];
int Color[Maxn][15];
inline void dfs(int x, int y, int z)
{
	if (y == -1) return ;
	if (Color[x][y]) return ;
	Color[x][y] = z;
	dfs(x, y - 1, z);
	for (int i = Begin[x]; i; i = Next[i])
	{
		int a = To[i];
		dfs(a, y - 1, z); 
	}
}
int main()
{
	scanf("%d%d", &N, &M);
	int x, y, z;
	for (int i = 1; i <= M; ++i)
	{
		scanf("%d%d", &x, &y);
		add_edge(x, y);
		add_edge(y, x);
	}
	scanf("%d", &Q);
	for (int i = 1; i <= Q; ++i)
		scanf("%d%d%d", &A[i].x, &A[i].y, &A[i].z);
	for (int i = Q; i >= 1; --i)
		dfs(A[i].x, A[i].y, A[i].z);
	for (int i = 1; i <= N; ++i)
		printf("%d\n", Color[i][0]);
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  vector<int> v(3);cin >> v;
  sort(v.begin(), v.end());
  int k; cin >> k;
  for(int i = 0; i < k; ++i)v[2]*=2;
  cout << v[0] + v[1] + v[2] << endl;
  return 0;
}


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

using namespace std;

#define rep(i,n) for(long long int i=0;i<n;i++)
#define rep1(i,n) for(long long int i=1;i<=n;i++)
#define repU(i,bottom,ceiling) for(long long int (i)=(bottom);(i)<=(ceiling);(i)++)
#define repD(i,ceiling,bottom) for(long long int (i)=(ceiling);(i)>=(bottom);(i)--)
#define pub push_back
#define pob pop_back
#define pf printf
#define sf scanf
#define ci(a) cin>>a
#define lco(a) cout<<a<<endl
#define co(a) cout<<a
#define vci(v) for(long long int i=0;i<v.size();i++) cin>>v[i]
#define vco(v) for(long long int i=0;i<v.size();i++){ cout<<v[i]<<' '; } cout<<endl
#define mp make_pair
#define fir first
#define sec second
#define clr(arr) memset((arr),0,sizeof(arr))
#define Re return 

typedef long long int ll;
typedef double db;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vb;
typedef vector<vector<double>> vvd;
typedef vector<long long int> vll;
typedef vector<vector<long long int>> vvll;
typedef pair<int,int> pii;

const string alphabet("abcdefghijklmnopqrstuvwxyz");
const vector<pair<int,int>> dir={{0,0},{1,0},{1,1},{0,1},{-1,1},{0,-1},{-1,-1},{0,-1},{1,-1}};
const long double Pi=3.141592653589793238462643383279502884197;
const long double Napier=2.71828182845904523536;
const int Inf=(int)2e9+1e8;
const int Mod=(int)1e9+7;

template<typename T,typename U>                                                   
inline pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir+r.fir,l.sec+r.sec};                                    
} 

template<typename T,typename U> 
inline pair<T,U> operator-(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir-r.fir,l.sec-r.sec};                                    
} 

template<typename T,typename U>                                                   
inline pair<T,U> operator*(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir*r.fir,l.sec*r.sec};                                    
}

template<typename T,typename U>                                                   
inline pair<T,U> operator/(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir/r.fir,l.sec/r.sec};                                    
}

template<typename T> inline void Swap(T *x,T *y){ T tem=*x; *x=*y; *y=tem; }

long long int rem(long long int n,long long int m){
	if(!m) return 0;
	return (n<0?(n%m)+m:(n%m));
}
  
             
/*The main code follows below*/


bool judge(int N_a,int A,int B,int q){
	int N_b=max(0,(N_a-1)/q);
	return ((B-N_b)/q+((B-N_b)%q!=0)<=(A-N_a+1));
}

int binsearch(int A,int B,int q){
	int upper=A+1;
	int lower=0;
	while(upper-lower>1){
		int mid=(upper+lower)/2;
		if(judge(mid,A,B,q)) lower=mid;
		else upper=mid;
	}
	return lower;
}

void solve(){
	int A,B,C,D;
	ci(A>>B>>C>>D);
	int q=max(A,B)/(1+min(A,B))+(max(A,B)%(1+min(A,B))!=0);
	int N_a=binsearch(A,B,q);
	int N_b=max(0,(N_a-1)/q);
	int L_part=N_a+N_b;
	for(;C<=min(D,L_part);C++){
		if(C%(q+1)) co('A');
		else co('B');
	}
	for(;C<=D;C++){
		if((A+B+1-C)%(q+1)) co('B');
		else co('A');
	}
	co(endl);
	return ;
}

int main(){
	int Q; ci(Q);
	rep(i,Q) solve();
	return 0;
}

Measured memory_bytes: 384
q, h, s, d = map(int, input().split())
n = int(input())
l = [4 * q, 2 * h, s, d / 2]
ans = 0
if n >= 2:
  a = l.index(min(l))
  if a == 0:
    ans = 4 * q * n
  elif a == 1:
    ans = 2 * h * n
  elif a == 2:
    ans = s * n
  elif a == 3:
    if n % 2 == 0:
      ans = n // 2 * d
    elif n % 2 == 1:
      ans = n // 2 * d
      b = l.index(min(l[:3]))
      if b == 0:
        ans += 4 * q
      elif b == 1:
        ans += 2 * h
      elif b == 2:
        ans += s
else:
  b = l.index(min(l[:3]))
  if b == 0:
    ans = 4 * q * n
  elif b == 1:
    ans = 2 * h * n
  elif b == 2:
    ans = s * n
print(ans)


Measured memory_bytes: 9104
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n,a[100000];
    long long int ans;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        ans=0;
        for(int i=0;i<n;i++)scanf("%d",&a[i]);
        sort(a,a+n);
        for(int i=0;i<n-1;i++){
            ans+=a[i]*(n-1-i);
        }
        printf("%lld\n",ans);
    }
}

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

int main(void)
{
  int h,w,x,y;
  cin >> h >> w;
  for(y=1;y<=h;y++){
    for(x=1;x<=w;x++){
      string s;
      cin >> s;
      if(s=="snuke"){
        printf("%c%d\n",(char)'A'+x-1,y);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int x,y;
    cin>>x>>y;
    if(y>=x*2 && y<=x*4){
        if(y%2==0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
/***** MAIN *****/
signed main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  if(n < 3200) cout << "red";
  else cout << s;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/

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

typedef long long ll;

int main(void)
{
    int a,b;
    cin >> a >> b;
    rep(i, 1500)
    {
        if(i == 0) continue;
        bool flag = true;
        if(8*i/100 != a) flag = false;
        if(i/10 != b) flag = false;
        if(flag)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
def popcount(x):
    c = 0
    while x > 0:
        if x & 1: c += 1
        x //= 2
    return c

def f(x):
    if x==0: return 0
    return f(x % popcount(x)) + 1

n = int(input())
X = input()
po = X.count('1')
pp = po + 1
pm = max(1, po - 1)
rp = rm = 0
for x in X:
    rp = (rp*2 + int(x)) % pp
    rm = (rm*2 + int(x)) % pm
bp = [0]*(n) # 2^i % (po+1)
bm = [0]*(n) # 2^i % (po-1)
bp[n-1] = 1 % pp
bm[n-1] = 1 % pm
for i in range(n-1, 0, -1):
    bp[i-1] = bp[i]*2 % pp
    bm[i-1] = bm[i]*2 % pm
for i in range(n):
    if X[i] == '0': ri = (rp + bp[i]) % pp
    else:
        if po-1 != 0: ri = (rm - bm[i]) % pm
        else:
            print(0)
            continue
    print(f(ri) + 1)


Measured memory_bytes: 25160